// Handler grvwObj_RowUpdating handling GridView RowUpdating Event protected void grvwObj_RowUpdating(object sender, GridViewUpdateEventArgs e) { //Declare local variables of name,id and stateid string name, id; int stateid, count = 0; // Assign state name to local variable name name = ((TextBox)grvwObj.Rows[e.RowIndex].Cells[1].Controls[0]).Text; // Assign State id to local variable id id = Convert.ToString(grvwObj.Rows[e.RowIndex].Cells[0].Text); DropDownList Countrydrp = ((DropDownList)grvwObj.Rows[e.RowIndex].Cells[3].FindControl("dropCountry")); // Declare local variable countryid and assign from drop down selected value int countryid = Convert.ToInt32(Countrydrp.SelectedValue); stateid = Convert.ToInt32(id); count = objState.Get_By_StateName(name); objState = objState.Get_By_Stateid(stateid); if ((count == 0) && (name != "")) { objState.Stateid = stateid; objState.Countryid = countryid; objState.Statename = name; objState.Update(); grvwObj.EditIndex = -1; BindGrid(); lblerrmsg.Text = Resources.MessageResource.errupdate.ToString(); } else if (objState.Statename == name) { objState.Stateid = stateid; objState.Countryid = countryid; objState.Statename = name; objState.Update(); grvwObj.EditIndex = -1; BindGrid(); lblerrmsg.Text = Resources.MessageResource.errupdate.ToString(); } else if (name == "") { lblerrmsg.Text = Resources.MessageResource.errnotempty.ToString(); } else { lblerrmsg.Text = Resources.MessageResource.erralready.ToString(); } }