Reputation: 13
I am using two dropdownlist in gridview. Total 5 to 7 rows in gridview. Bind ProductId and product name in First Dropdown. when select product that time databound in second dropdown. so how to findout row number when fire dropdown's event.
Upvotes: 1
Views: 6396
Reputation: 460098
I assume the property you're looking for is GridViewRow.RowIndex
. To get the reference to the row from the SelectedIndexChanged
event from your DropDownLis(s), you can use it's NamingContainer
property:
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");
}
Upvotes: 5
Reputation: 22323
You can handle SelectedIndexChanged event of DropDownList.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gvr = (GridViewRow)((DropDownList)sender).Parent.Parent;
string rowNumber= GridView1.DataKeys[gvr.RowIndex].Value.ToString();
}
Upvotes: 1