I have a gridview. Here are my columns: The column choose's control is a dropdown with 2 values: yes/no
No Name Choose
1 Meh Yes/No
On edit event I want to insert the selected value of the dropdown in the database of the current edited cell.
I have a gridview. Here are my columns: The column choose's control is a dropdown with 2 values: yes/no
No Name Choose
1 Meh Yes/No
On edit event I want to insert the selected value of the dropdown in the database of the current edited cell.
protected void GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = ((GridView)sender).Rows[e.RowIndex];
DropDownList ddl = (DropDownList)row.FindControl("DdlChoose");
bool yes = ddl.SelectedValue == "Yes";
SaveData(params); // pseudo-code
}
1st thing first, i'd suggest data binding, and apply changes to the Database as bulks and not one at a time, unless forced to by definition.
2nd, each row have a key, then it is no problem to execute a Update the Row by UPDATE mytable SET choose=new_value WHERE key_column=rowkey.
EDIT : DatagridView Binding to SQL Database example can be found : http://csharp.net-informations.com/datagridview/csharp-datagridview-sql-server.htm