如何获取GridView行的索引 [英] How to get index of the gridview row

查看:68
本文介绍了如何获取GridView行的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取其子控件正在回发的网格视图的行索引.我知道控制导致回发并找到其父容器的方法,该容器返回网格视图行,然后找到其索引.我希望在RowDataBound事件中检查selectedrow索引并设置其格式.是否有其他属性或设置可以直接在任何子控件回发上直接发出网格视图的选定索引

How can i get row index of the grid view whose child control is doing post back. I know the way of getting control causing post back and finding its parent container which returns grid view row and then find its index. I want this in a RowDataBound event to check selectedrow index and formatting the same. Is there any other property or settings which directly emits selected index of the grid view on any child control post back

例如,如果一行中有一个下拉列表,并且gridview中有某些行.然后我想要gridview rowindex,其中由于gridview行中的dropdowlist而发生回发.

For example if there is a dropdownlist in a row and there are certain rows in a gridview. Then i want gridview rowindex where postback happens due to that dropdowlist in the gridview row.

推荐答案

您可以通过

You can get the index of the row in RowDataBound via the RowIndex property:

protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int index = e.Row.RowIndex;
    }
}

您可以通过

  • childControl.NamingContainer =>
  • GridViewRow =>
  • RowIndex
  • childControl.NamingContainer =>
  • GridViewRow =>
  • RowIndex

例如在 DropDownList.SelectedIndexChanged 事件中:

protected void DropDownList1_SelectedIndexChanged(Object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList) sender;
    GridViewRow row  = (GridViewRow)  ddl.NamingContainer;
    int index        = row.RowIndex;
}

最后:由于您已经提到了检查选中的行索引" ,因此,如果您实际上正在查找 GridView的选中行索引本身,就有一个属性:

Finally: since you've mentioned " to check selectedrow index", if you're actually looking for the selected row index of the GridView itself, there's a property just for this:

这篇关于如何获取GridView行的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆