|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Perform insert to gridview/tableI am working with VS2005 and asp.net 2.0. I would like to perform an insert to a table/gridview by clicking a button on a web form (not part of the gridView rendering). I can do this using the VS2003 methods of sqldataadapter, etc by running the insert, etc, but without the handy "visual" control in VS2003. Can I do a similar thing using the sqldatasource, and having it hooked to a gridview? I do not want to use the "embedded" feature of the gridview for inserting, etc. can i perform a programatic insert using the sqldatasource? Any info will help, Thanks, eric Eric,
There is no native ability in the GridView to insert data, only update and delete. If you take a look at my blog, I have an entry there that shows how to get around this. If you only want to get this functionality out of the Sql Data Adaptor, you will find that the events and methods of the Sql Adaptor are just about the same as the Data Adaptor which I write about in the same entry on my blog. Hope this helps, http://blog.binaryocean.com/InsertRowsWithAGridViewII.aspx -Andrew Show quoteHide quote "Bernie Niblets" <e.m***@verizon.net> wrote in message news:121h6qkhi8lljf7@corp.supernews.com... > Hello Group, > > I am working with VS2005 and asp.net 2.0. > > I would like to perform an insert to a table/gridview by clicking a button > on a web form (not part of the gridView rendering). I can do this using > the VS2003 methods of sqldataadapter, etc by running the insert, etc, but > without the handy "visual" control in VS2003. Can I do a similar thing > using the sqldatasource, and having it hooked to a gridview? I do not > want to use the "embedded" feature of the gridview for inserting, etc. > > > can i perform a programatic insert using the sqldatasource? > > Any info will help, > > Thanks, > > eric Andrew Robinson wrote:
Show quoteHide quote > Eric, I will check it out!> > There is no native ability in the GridView to insert data, only update and > delete. > > If you take a look at my blog, I have an entry there that shows how to get > around this. If you only want to get this functionality out of the Sql Data > Adaptor, you will find that the events and methods of the Sql Adaptor are > just about the same as the Data Adaptor which I write about in the same > entry on my blog. > > Hope this helps, > > http://blog.binaryocean.com/InsertRowsWithAGridViewII.aspx > > -Andrew > Hello Andrew, thankss Yes you can do a programmatic insert.
Suppose you have a LinkButton called btnInsert, a list of input Textboxes to get the information for the insert and a SqlDataSource called sqldatasource1 that has been properly setup with InsertCommand, InsertParameters etc. Within the click event handler of btnInsert, gather all the information from your input textboxes and assign them to the sqldatasource.InsertParameters collection. Finally call sqldatasource1.Insert() 'Small example Protected Sub btnInsert_Click(sender As Object, args As EventArgs) sqldatasource1.InsertParameters("Col1").DefaultValue = TextBox1.Text sqldatasource1.InsertParameters("Col2").DefaultValue = TextBox2.Text Page.Validate("InsertGroup") If Page.IsValid Then sqldatasource1.Insert End If End Sub Good luck.
GridView w/ ObjectDataSource w/ Business object layer
GridView, ObjectDataSOurce, and enum parameter for select Web UserControl (ascx) and UrlProperty attribute Gridview custom sort - works but always sorts ascending Scrolling DG w/a Fixed Header Datalist formatting questions Adding client side code to RadioButtonList control item??? DataGrid1.DataSource = ds.Tables(2) Treeview SelectedNodeChanged event not firing GridView custom control and post back issues |
|||||||||||||||||||||||