现在的位置: 首页 > 综合 > 正文

GridView 中的各种查找

2013年10月31日 ⁄ 综合 ⁄ 共 897字 ⁄ 字号 评论关闭

在RowDataBound 和RowCreated 事件里面 查找

1、当前行中的控件 e.Row.FindControl("TextBox1");

2、当前行              e.Row.RowIndex;

3、当前行的主键值  GridView1.DataKeys[e.Row.RowIndex].Value.ToString();

在RowCommand事件里面 查找

  RowCommand事件是GridView中的按钮触发的事件。只有这三个属性。

    

  e.CommandName;       //判断是哪个按钮。

  e.CommandArgument; //你可以绑定任何你认为有用的值,默认是当前按钮所在的行号
  e.CommandSource;    //数据源

 

在GridView中的按钮Click事件里面

 ImageButton button = (ImageButton)sender;
 ((GridViewRow)((DataControlFieldCell)button.Parent).Parent).RowIndex;//当前的行数
  GridView1.DataKeys[Row_num].Value.ToString(); //当前行的主键值 

  (button.Parent.Parent as GridViewRow).FindControl("TextBox1");或

  gvcgGrid.Rows[Row_num].FindControl("TextBox1");//查找当前行中的其他控件

 

 

查找 <FooterTemplate>模板中的控件

GridView1.FooterRow.FindControl("TextBox1") as TextBox

查找 <EmptyDataTemplate>模板中的控件

GridView1.Controls[0].Controls[0].Controls[0].FindControl("TextBox1") as TextBox;

 

 

在这里我之列了一些基本的查找,一个非常有意思的属性是Parent你可以根据他查找到你任何想要的东西。

 

 

 

 

 

 

 

 

 

 

【上篇】
【下篇】

抱歉!评论已关闭.