gridview edit data and save the data in database usig c#

Posted by Ramakrishna188 under ASP.NET on 2/24/2012 | Points: 10 | Views : 9068 | Status : [Member] | Replies : 2
hi all
Please send me any my requirement is I have one girdview with 6 rows first row with checkbox controls and second row with edit link buttons
When I click the editlinkbutton I want to modify the that column all cells and I click the another editlinkbutton I want to modify the that colum all cells. Lastly I will check the check boxes which I edit the columns I I want to store the data in database which I check the check boxes columsn.




Responses

Posted by: Neer on: 2/24/2012 [Member] Starter | Points: 25

Up
0
Down
Belox Is the Example Code of updating and storing that to c#,

---------------------------------------
public void BindDataToGridView()
{
Database db = new Database();

string str = "select * from ABDatabase";

GridView1.DataSource = db.GetDataReaderQuery(str);
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindDataToGridView();

}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindDataToGridView();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Label lblMemID = (Label)row.FindControl("lblMemberID");
TextBox txtApproval = (TextBox)row.FindControl("txtApprovalStatus");
TextBox txtMembOption = (TextBox)row.FindControl("txtMembersipOption");
TextBox txtCategory = (TextBox)row.FindControl("txtBusinessCategory");
TextBox txtUName = (TextBox)row.FindControl("txtUserName");
TextBox txtContPer = (TextBox)row.FindControl("txtContactPerson");
TextBox txtPwd = (TextBox)row.FindControl("txtPassword");
TextBox txtAddr = (TextBox)row.FindControl("txtAddress");
TextBox txtPin = (TextBox)row.FindControl("txtPinCode");
TextBox txtWeb = (TextBox)row.FindControl("txtWebsite");
TextBox txtemail = (TextBox)row.FindControl("txtEmail");
TextBox txtPh = (TextBox)row.FindControl("txtPhone");
TextBox txtMob = (TextBox)row.FindControl("txtMobile");
TextBox txtDesc = (TextBox)row.FindControl("txtDescription");


GridView1.EditIndex = -1;
Database db = new Database();
string str = "update ABDatabase set MembershipID='" + Convert.ToInt16(txtMembOption.Text) + "',BusinessCategory='" + txtCategory.Text + "',UserName='" + txtUName.Text + "',ContactPerson='" + txtContPer.Text + "',Password='" + txtPwd.Text + "',Address='" + txtAddr.Text + "',PinCode='" + txtPin.Text + "',Website='" + txtWeb.Text + "',Email='" + txtemail.Text + "',Phone='" + txtPh.Text + "',Mobile='" + txtMob.Text + "',Description='" + txtDesc.Text + "' where MemberID=" + lblMemID.Text + " ";
db.ExecuteNonQuery1(str);

BindDataToGridView();

}
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
GridView1.EditIndex = -1;

}

-Neer

Ramakrishna188, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 2/24/2012 [Member] Starter | Points: 25

Up
0
Down
hi.Refer the below link for more clearance
http://www.dotnetcode.in/2011/12/updateedit-and-delete-in-grid-view.html


Ramakrishna188, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response