- Within Grid View RowDataBound method, we can bind the drop down lists in Edit item template.
- Add following codes within RowEditing and on RowCancellingEdit methods.
- Write the code as follows for row updating.
[code]
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
TextBox txtAddress = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtAddress");
DropDownList ddlLocation = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlLocation");
CheckBox chkEditActive = (CheckBox)GridView1.Rows[e.RowIndex].FindControl("chkEditActive");
string custListId = GridView1.DataKeys[e.RowIndex].Value.ToString();
string address = txtAddress.Text;
string locationListId = string.Empty;
bool isActive = false;
if (chkEditActive.Checked)
{
isActive = true;
}
if(ddlLocation.SelectedIndex > 0)
{
locationListId = ddlLocation.SelectedValue;
}
bool status = myService.updateCustomer(locationListId, address, isActive, custListId);
GridView1.EditIndex = -1;
bindDataToGrid();
}
catch (Exception ex)
{
throw ex;
}
}
[/code]
- Grid view design
[code]
No comments:
Post a Comment