ASP.NET Gridview ItemTemplate Dropdown

I am using C # ASP.net and a relative new one for it, and you need to follow below.

In my VS2010 web application project, I have webformwith Gridviewwhich retrieves data from a table.

In the grid, I have CommandfiledButton (column1) and an element template with Dropdownlist(column2).

Use the case, the user first selects one listitemof the 3 elements of the list (H, L and M), and then selects the command button.

I can't figure out how to extract the selected listitemfrom the selected row

protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{

    GridViewRow row = GridView2.SelectedRow;
    Label4.Text = "You selected " + row.Cells[4].Text + "."; 
    Label5.Text = "You selected this list item from dropdownlist " + ???? ; 
}

Thanks in advance.

+3
source share
1 answer

GridViewRow FindControl ( ), . , DropDownList MyDropDown, :

GridViewRow row = GridView2.SelectedRow;
DropDownList MyDropDown = row.FindControl("MyDropDown") as DropDownList;
string theValue = MyDropDown.SelectedValue;
// now do something with theValue

GridView. , row.Cells[#], / GridView.

+2

All Articles