How save data in gridview from footer?
-
i have been running ths code but unabale to save ingridview from footer using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.Conne… protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bind(); } } protected void bind() { try { con.Open(); SqlCommand cmd = new SqlCommand("select * from tbbook", con); SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); GridView1.DataSource = dt; GridView1.DataBind(); con.Close(); } catch (Exception) { //somethng wrong } } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { { Int32 lbl, text3; string text1, text4; GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; lbl = Convert.ToInt32(((Label)row.FindControl(… text1 = ((TextBox)row.FindControl("TextBox1")).T… text3 = Convert.ToInt32(((TextBox)row.FindContro… text4 = ((TextBox)row.FindControl("TextBox3")).T… con.Open(); SqlCommand cmd = new SqlCommand("update tbbook set bookauthor=@aut,bookprice=@prc,bookimage… where bookid=@bid", con); cmd.Parameters.Add("@bid", SqlDbType.Int).Value = lbl; cmd.Parameters.Add("@aut", SqlDbType.VarChar, 50).Value = text1; cmd.Parameters.Add("@prc", SqlDbType.Int).Value = text3; cmd.Parameters.Add("@img", SqlDbType.VarChar, 50).Value = text4; cmd.ExecuteNonQuery(); con.Close(); GridView1.EditIndex = -1; bind(); } } protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; bind(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; bind(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Int32 lbl, text3; string text1, text4; GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; lbl = Convert.ToInt32(((Label)row.FindControl(… con.Open(); SqlCommand cmd = new SqlCommand("delete from tbbook where bookid = @bid ", con); cmd.Parameters.Add("@bid", SqlDbType.Int).Value = lbl; cmd.ExecuteNonQuery(); con.Close(); bind(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "save") { Int32 text3; string text1, text4; GridViewRow row = (GridViewRow)GridView1.FooterRow; text1 = ((TextBox)row.FindControl("TextBox4")).T… text3 = Convert.ToInt32(((TextBox)row.FindContro… text4 = ((TextBox)row.FindControl("TextBox6")).T… con.Open(); SqlCommand cmd = new SqlCommand("insert into tbbook values(@aut,@prc,@img)", con); cmd.Parameters.Add("@aut", SqlDbType.VarChar, 50).Value = text1; cmd.Parameters.Add("@prc", SqlDbType.Int).Value = text3; cmd.Parameters.Add("@img", SqlDbType.VarChar, 50).Value = text4; cmd.ExecuteNonQuery(); con.Close(); bind(); } } }
-
Answer:
I am not sure that bind() is correct in the GridView1_RowEditing1 method. It may be overwriting your edits.
Mushiana at Yahoo! Answers Visit the source
Related Q & A:
- How to set column as readonly on Gridview?Best solution by Stack Overflow
- How to sort a particular page in gridview?Best solution by dotnetfox.com
- How To Sort a GridView Column When a Header Is Clicked?Best solution by Stack Overflow
- How save is the blood supply in the USA?Best solution by aids.org
- How can I save my data on the Internet?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.