GridView使用一些记录

现在有个项目开始使用ASP.NET 2.0开发,在开发过程中关于GridView的使用的一些零星的记录
1.TemplateField中的绑定

None.gif < asp:TemplateField >
ExpandedBlockStart.gifContractedBlock.gif                        
< ItemTemplate > <% dot.gif Eval("OCompany.Name" %> </ ItemTemplate >
None.gif                    
</ asp:TemplateField >

2.通过CheckBox得到选择行的主健值(GridView支持多主健)
None.gif          private   string  GetSelectId()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
//EnsureChildControls();
InBlock.gif
            GridView gvlist1 = (GridView)this.Controls[0].FindControl("gvlist");
InBlock.gif
InBlock.gif            
int icount = gvlist1.Rows.Count;
InBlock.gif
InBlock.gif            
string id = string.Empty;
InBlock.gif
InBlock.gif            
for (int i = 0; i < gvlist1.Rows.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                CheckBox cb 
= (CheckBox)gvlist1.Rows[i].FindControl("cb_id");
InBlock.gif
InBlock.gif                 
//得到选中行的信息
InBlock.gif
                if (cb.Checked == true)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    DataKey dkr 
= gvlist1.DataKeys[i];
InBlock.gif
InBlock.gif                    id 
= dkr.Value.ToString();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return id;
ExpandedBlockEnd.gif        }

3.动态创建TemplateField
None.gif private   void  TemplateColumn(GridView gvlist,  string  column, GridListAttribute att)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            TemplateField tf 
= new TemplateField();
InBlock.gif
InBlock.gif            tf.HeaderText 
= att.HeaderText;
InBlock.gif            tf.HeaderStyle.Width 
= Unit.Parse(att.Width);
InBlock.gif
InBlock.gif            ColumnTemplate temp 
= new ColumnTemplate();
InBlock.gif
InBlock.gif            temp.Column 
= att.Column;
InBlock.gif
InBlock.gif            tf.ItemTemplate 
= temp;
InBlock.gif
InBlock.gif            gvlist.Columns.Add(tf);
InBlock.gif     
InBlock.gif            
ExpandedBlockEnd.gif        }

None.gif
ColumnTemplate类
None.gif public   class  ColumnTemplate : ITemplate
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
//第一个模板列 
InBlock.gif
    public void InstantiateIn(Control container)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        LiteralControl l 
= new LiteralControl();
InBlock.gif        l.DataBinding 
+= new EventHandler(this.OnDataBinding);
InBlock.gif        container.Controls.Add(l);
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public void OnDataBinding(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
InBlock.gif            LiteralControl lt 
= (LiteralControl)sender;//LiteralControl发送绑定请求
InBlock.gif

InBlock.gif            GridViewRow container 
= (GridViewRow)lt.NamingContainer;
InBlock.gif
InBlock.gif            lt.Text 
= DataBinder.Eval(container.DataItem, column).ToString();
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值