日期:2014-05-18  浏览次数:20382 次

分不多了,请教!在DATAGRID中如何取得摸板列中的LABEL的值?
在DATAGRID中添加摸版列放入LABEL,假如LABEL的TEXT数据绑定的是数据库中某表的“ID”,这时,在DATAGRID外有一个BUTTON,单击事件中如何获得在DATAGRID中所有LABEL的TEXT值?


分虽然不多,不好意思,谢谢大家了!

------解决方案--------------------
foreach( DataGridItem dgi in DataGrid1.Items )
{
Label lbid = (Lable)dgi.FindControl( "labelid ");
if( lbid != null )
...
}
------解决方案--------------------
protected void GridView1_RowDataBound(object sender , GridViewRowEventArgs e)
{

e.Row.Attributes.Add( "onmouseover ", "this.style.backgroundColor= 'red ' ");
e.Row.Attributes.Add( "onmouseout ", "this.style.backgroundColor= 'silver ' ");
e.Row.Attributes.Add( "onclick ", "return confirm( 'Sure ? '); ");
e.Row.Cells[0].Attributes.Add( "onclick ", "return confirm( 'OK! '); ");
Label lb = (Label)e.Row.FindControl( "Label1 ");
if (lb != null)
{
Response.Write(lb.Text);
}
Label lb2 = (Label)e.Row.FindControl( "Label2 ");
if(lb2!=null)
{
Response.Write(lb2.Text);

}


}
------解决方案--------------------
假设模板列为第0列,则 取第0行的label值

this.lbid.Text=((Label)this.dgi.Items[0].Cells[0].FindControl( "LB4 ")).Text;