I have a GridView which has the property:
OnRowUpdating="GridViewRowUpdateEventHandler"
Within the GridView, I have the following control:
<asp:TemplateField HeaderText="Progress" SortExpression="progress">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="0">Incomplete</asp:ListItem>
<asp:ListItem Value="1">Complete</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
The GridViewRowUpdateEventHandler
looks like this:
protected void GridViewRowUpdateEventHandler(object sender, GridViewUpdateEventArgs e)
{
SqlConnection connection;
SqlCommand command;
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
DropDownList ddlPriority = (DropDownList)row.FindControl("DropDownList1");
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
{
using (command = new SqlCommand(@"update table1 set priority = @priority where id = @id", connection))
{
command.Parameters.Add("@priority", SqlDbType.Int, 1).Value = ddlPriority.SelectedValue;
command.Parameters.Add("@id", SqlDbType.Int, 1).Value = row.RowIndex;
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
}
GridView1.DataBind();
}
I am getting no error messages at all, and the relevant row in the database is not being updated. Anyone know why?
Could it be that I am looking at the wrong cell Cells[5]
? Or maybe because I have nothing in page_load? Or maybe something else?