GridView Edit
Guys I am stuck with including Edit in my Grid View.. The Specifications of my problem are as follows:
geniusvishal
Junior Poster in Training
58 posts since Jan 2012
Reputation Points: 9
Solved Threads: 4
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
GridView1.EditIndex = e.NewEditIndex;
bindGvEdit();
}
catch (Exception ex)
{
lblUpdate.Text = ex.Message;
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
objCust.CustId = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
objCust.CustAddress = txtCustAddress.Text;
objCust.UpdateNewUser();
GridView1.EditIndex = -1;
bindGvEdit();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
ViewState["CustId"] = e.CommandArgument;
objCust.CustId = Convert.ToInt32(e.CommandArgument);
DataSet dsSelectNewUser = objCust.SelectNewUser();
txtCustAddress.Text = dsSelectNewUser.Tables[0].Rows[0].ItemArray[2].ToString();
}
}
I am actually inserting the value of CustAddress into txtCustAddress.TextBox and then using this textbox value into my Gridview.. But to my knowledge i found out that CustAddress is not getting any value on Debbuging.. Plz help to rectify the problem...
geniusvishal
Junior Poster in Training
58 posts since Jan 2012
Reputation Points: 9
Solved Threads: 4
Guys got the solution for this :
No need for including Row command... Only rowUpdating is enough....
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
objCust.CustId = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
objCust.CustAddress = ((TextBox)row.Cells[2].Controls[0]).Text;
objCust.UpdateNewUser();
GridView1.EditIndex = -1;
bindGvEdit();
}
geniusvishal
Junior Poster in Training
58 posts since Jan 2012
Reputation Points: 9
Solved Threads: 4