I can't find a solution for this so, I really need some expert to help out. I'm trying to insert data from the gridviews footer thru a button. In the footer I have a button that adds a record to the grid when I execute it but when I'm trying to type in some
values it does not allow any typing. I have a gridview doing the same for edit and update but inside the gridview and from a link button, and that is working gracefully. So, also worth mentioning I'm trying to do this from the Gridview_OnRowCommand(..... This
thing is killing me and I really need this to work before tomorrow, so if anyone had done this before plz help me that would so much appreciated. Thank your time in advance.
Thanks for you respond. It seems that people have different oppinion in regards to this. I'm using link to entities and an entity datasource. However, I'm just happy if I can get this to work, so If you have a concrete sample please share that with me, I
really need to finish this so that would be much helpful. I just looked at your link and I'm really not interested to support any businesses especially if they using forums as a pitch for new customers, if you have any helpful tips in regards to LINQ and link
to entities datasource because it is a hugh difference, then let me know.
btw. I'm using textboxes for edit and update which works fine, my problem is INSERT of data from a button in a gridview.
That is what I have. Also, shouldn't be "context.FORECASTCOMMODITY.AddObjects(...."? As I mentioned earlier it doesn't allow any typing in the blank records space? Any ideas? So I should have a method for AddObject() and not just?
2)Please convert your columns columns into TemplateField,and then double click the button there,and in the Insert_Click plz do inserting statement。Don't forget to reset DataSource and call DataBind again after inserting。
rZebra
Member
18 Points
13 Posts
How to insert data to database from a button in the gridview footer using link to entities?
Feb 28, 2012 08:29 PM|LINK
Hí,
I can't find a solution for this so, I really need some expert to help out. I'm trying to insert data from the gridviews footer thru a button. In the footer I have a button that adds a record to the grid when I execute it but when I'm trying to type in some values it does not allow any typing. I have a gridview doing the same for edit and update but inside the gridview and from a link button, and that is working gracefully. So, also worth mentioning I'm trying to do this from the Gridview_OnRowCommand(..... This thing is killing me and I really need this to work before tomorrow, so if anyone had done this before plz help me that would so much appreciated. Thank your time in advance.
protected void AddNewRecord(object sender, EventArgs e) { GridView1.ShowFooter = true; GridView1.DataBind(); } protected void GridView1_OnRowCommand1(object sender, GridViewCommandEventArgs e) { TCETModel.TCET context = new TCETModel.TCET(); if (e.CommandName.Equals("EmptyInsert")) { ForecastCommodity ForecastCommodity = new ForecastCommodity(); GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer; Label lblForecastAmount = (Label)GridView1.Rows[row.RowIndex].FindControl("ForecastAmount"); Label lblMonth = (Label)GridView1.Rows[row.RowIndex].FindControl("Month"); context.AddObject(lblForecastAmount.Text, lblMonth.Text); context.SaveChanges(); GridView1.DataBind(); } if (e.CommandName.Equals("Insert")) { GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer; Label lblForecastAmount = (Label)GridView1.Rows[row.RowIndex].FindControl("ForecastAmount"); Label lblMonth = (Label)GridView1.Rows[row.RowIndex].FindControl("Month"); context.AddObject(lblForecastAmount.Text, lblMonth.Text); context.SaveChanges(); GridView1.DataBind(); }sravanisrav
Member
470 Points
107 Posts
Re: How to insert data to database from a button in the gridview footer using link to entities?
Feb 29, 2012 06:15 AM|LINK
Hello rZebra,
Instead of using labels in your code use textboxes for edit and update.
In gridview it worked because the labels uses two way binding there, which allows us to edit.
For more information visit http://www.bestdotnettraining.com/Online/Training/ASP-NET/Databound-Controls/71
Thanks & Regards
Sravani
rZebra
Member
18 Points
13 Posts
Re: How to insert data to database from a button in the gridview footer using link to entities?
Feb 29, 2012 07:51 AM|LINK
Thanks for you respond. It seems that people have different oppinion in regards to this. I'm using link to entities and an entity datasource. However, I'm just happy if I can get this to work, so If you have a concrete sample please share that with me, I really need to finish this so that would be much helpful. I just looked at your link and I'm really not interested to support any businesses especially if they using forums as a pitch for new customers, if you have any helpful tips in regards to LINQ and link to entities datasource because it is a hugh difference, then let me know.
btw. I'm using textboxes for edit and update which works fine, my problem is INSERT of data from a button in a gridview.
Thx
vish02chouha...
Member
303 Points
253 Posts
Re: How to insert data to database from a button in the gridview footer using link to entities?
Feb 29, 2012 08:40 AM|LINK
Show me Your AddObject() method
rZebra
Member
18 Points
13 Posts
Re: How to insert data to database from a button in the gridview footer using link to entities?
Feb 29, 2012 11:56 AM|LINK
Hmm, I'm I missing something??
That is what I have. Also, shouldn't be "context.FORECASTCOMMODITY.AddObjects(...."? As I mentioned earlier it doesn't allow any typing in the blank records space? Any ideas? So I should have a method for AddObject() and not just?
if (e.CommandName.Equals("Insert")) { GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer; Label lblForecastAmount = (Label)GridView1.Rows[row.RowIndex].FindControl("ForecastAmount"); Label lblMonth = (Label)GridView1.Rows[row.RowIndex].FindControl("Month"); context.AddObject(lblForecastAmount.Text, lblMonth.Text);Thanks again for your time. Rz
So this piece beneath adding a blank record in the footer --
protected void AddNewRecord(object sender, EventArgs e)
{
GridView1.ShowFooter = true;
GridView1.DataBind();
}
I have this code for the insert button in the footer
protected void btnInsert_Click(object sender, EventArgs e)
{
}
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to insert data to database from a button in the gridview footer using link to entities?
Mar 01, 2012 01:17 AM|LINK
Hello rZeba:)
1)Please make sure that your ShowFooterRow=True。
2)Please convert your columns columns into TemplateField,and then double click the button there,and in the Insert_Click plz do inserting statement。Don't forget to reset DataSource and call DataBind again after inserting。
Here's a nice sample for you to view with:
http://geekswithblogs.net/casualjim/archive/2005/08/29/51360.aspx