如何在gridview中的fire下拉事件中找到rowindex

时间:2012-03-29 07:17:38

标签: asp.net

我在gridview中使用了两个下拉列表。 gridview中共有5到7行。   在First Dropdown中绑定ProductId和产品名称。当选择产品时,数据包在第二个下拉列表中。   所以如何在火灾下拉事件中找到行号。

2 个答案:

答案 0 :(得分:2)

我认为您正在寻找的属性是GridViewRow.RowIndex。要从DropDownLis中获取SelectedIndexChanged事件中的行的引用,您可以使用它的NamingContainer属性:

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
   DropDownList ddl = (DropDownList)sender;
   GridViewRow row = (GridViewRow)ddl.NamingContainer;
   int rowIndex = row.RowIndex;
   // if you want to get the reference to the other DropDown in this row
   DropDownList ddl2 = (DropDownList)row.FindControl("DropDownList2");
}

答案 1 :(得分:1)

您可以处理DropDownList的SelectedIndexChanged事件。

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
        GridViewRow gvr = (GridViewRow)((DropDownList)sender).Parent.Parent;
        string rowNumber= GridView1.DataKeys[gvr.RowIndex].Value.ToString();
}