In a recent project, you need to add a DropDownList to the ItemTemplate in the GridView, and when I choose this DropDownList, he needs to return the data to the server:
The following figure:
At first I wanted to write in the <RowDataBound> of the GridView, but DropDownList has no commandname attributes.
So only in the DropDownList Selecedindexchanged event wrote, the specific steps:
In the GridView Edit State, double-click DropDownList to enter the following event, the code is as follows:
protected void DropDownList1_SelectedIndexChanged (object sender, EventArgs e)
{
DropDownList Type = sender as DropDownList;
TableCell cell = (TableCell) type.parent;
GridViewRow item = (gridviewrow) cell. Parent;
String sql = "Update t_memberinfo set yx=" + type.selectedvalue+ "and where id=" +item. Cells[0]. Text;
Dal. RUNSQL (SQL);
Gridviewbind (); //gridview Binding Events
}