Data Controls insert rows into gridview then insert rows from gridview into SQL Table

Hello there, I'm still new at performing miracles with code Idea. Currently I am having trouble with my latest coding adventure

I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for the gridview in the middle is for the user to see a list of all entries and edit them if a mistake is noticed before submitting the lot to the database.

I've gotten tunnel vision searching the web for a solution or a clue on how to do this, but have not found anything really related to this particular scenario. Smile any ideas would be greatly appreciated.

A learning experience is one of those things that say, 'You know that thing you just did? Don't do that.'
1/24/2008 3:19:46 PM 72751 articles. 3 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 1

Create an object which will represent a record in a gridview. Store collection of objects (those ones which are currently selected but not inserted to database yet) in a session, because you want to keep this info between postbacks. Use object data source to display data in a grid view and to update/insert information to database.

1/24/2008 4:30:55 PM

just a suggestion

well i was thinking you have the gridview and then you have all your normal controls then you have a "add to grid button" or something like that, then in code behind you just make a new row and add it to the gridview. (making it appear in the gridview), then you have the actual save button which in code behind will take all the rows put them into a datatable and then you can do like a sqlbulkcopy to the database...... what do you think?

my friends call me MOI
1/24/2008 4:32:09 PM

Thank you both for your replies.

I've been thinking along the same tracks, but got a bit confused when I thought about how to handle the editing the rows in the gridview. if I'm puting values in from a textbox, all should be no real problem, but I'm also going to be using databound DropDownLists for a couple fields as well. Will I add them and a datasource to populate them in the "edit" row of the gridview.

 I was also wonder how to save the "row objects" in a session? Smile

Thanks again for taking the time to help.

A learning experience is one of those things that say, 'You know that thing you just did? Don't do that.'
1/25/2008 1:27:04 PM

onrow command if( ==update)


SqlDataSource.updateparameter["CreatedById"].DefaultValue = gridview.rows[gridview.editrowindex].findcontrol("ddlBusGroup").SelectedValue.ToString();


try something like that? is that what youre asking?

my friends call me MOI
1/25/2008 6:52:13 PM


 I am new to coding too and I'm having the same problem where I created different controls using Ajax for sorting and Textbox controls with the submit button and a Gridview in the bottom for the users to see what they input and edit or delete.  I am using C#.  So Far,  I have created the dropdowncontrols to be selected from different data tables and entered text from the text box controls on top which I wanted to go to another datatable when the user submits the submit button...The ObjectDataSource "the code below" is connected to the table that I want the new data to go to and the grid view to show that entered data.  I need help on what or how to code for the SubmitButton_Click and Page_Load ... 

<asp:ObjectDataSource ID="ObjectDataSource" runat="server"

DeleteMethod="Delete" InsertMethod="Insert"

OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"



and I have used this for the insert parameters...


<asp:SessionParameter Name="UserId" SessionField="@UserId" Type="Object" />

<asp:SessionParameter Name="FirstName" SessionField="@FirstName" Type="String" />

<asp:SessionParameter Name="LastName" SessionField="@LastName" Type="String" />

<asp:ControlParameter ControlID="TasksDropDown" Name="PrimaryTask"

PropertyName="SelectedValue" Type="String" />

<asp:ControlParameter ControlID="HoursWorkedDropDown" Name="HoursWorked"

PropertyName="SelectedValue" Type="String" />

<asp:ControlParameter ControlID="DateWorkedTextBox" Name="DateWorked"

PropertyName="Text" Type="DateTime" />

<asp:ControlParameter ControlID="TaskCommentTextBox" Name="TaskComments"

PropertyName="Text" Type="String" />


I didn't put ControlParameter for the delete and update parameters...I am not sure if I have to do it for each..

7/10/2008 4:40:01 PM

 welllllll your question has so many answers becuase there are so many options of how to do things... try looking at some examples and finding what you want to do. if ur just trying to "learn" then try them all


the second one uses templatefields, i would suggest learning these and not being scared of them. THEY KICK A$$ A(dollars)  

my friends call me MOI
7/10/2008 8:21:32 PM
Thank you for your suggestion.  But I was sort of looking a code something like below for the selectedValues from the controls table to be submitted from the Submit button to another table.  I am not using the insert button on the Gridview.  Grid view is just for editing and deleting what the user input from the controls.  The controls tables and the Gridview table is different.  Most of the examples shown is working from the same table.  Please see where I put the question marks...  Thanks,protected void SubmitButton_Click1(object sender, EventArgs e) 


SqlConnection conn = new SqlConnection("server=.;database=Bet;Integrated Security=SSPI ");


string sql = "insert into TasksWorked (PrimaryTask,Classifications,ProjectName,TaskComments) values (@PrimaryTask,@Classifications,@ProjectName,@TaskComments)";

SqlCommand cmd = new SqlCommand(sql, conn);






7/11/2008 4:20:56 PM

i dont get that "controlparamaters" property when i make a sqlcommand, but the intelisense should tell you, im pretty sure its the value of the param, make sure its teh same datatype and length that your sql will take. if this is on click like it looks like it is, you might want to make your params before like this

sqlparam param = new sqlparam("name", value);


although i think ur going to be using sqlparameters you dont need to use controlparameters, control parameters are used when ur sql knows where to get teh information from ahead of time, not sure which one ur looking for but hopefully this helps, ur right there......


my friends call me MOI
7/11/2008 10:29:46 PM

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Submit Form to insert data into SQL and display with a gridview (edit as well) below how do i insert data into sql table?
I have an page that has a simple form where a user can submit customers information. Below that I have a gridview which displays customer information submited by the user who is logged in. I have the gridview displaying, sorting and updating as I want however I can't figure out how to bind a button click to insert data into the customer table and then have it refresh the gridview when they submit. Here is the basic code; (I am using AJAX for a calendar when a user wants to edit an appointment date) &lt;div class="leftBar"&gt; <div align=center&...

Insert a row int DB Table using GridView Control
Dear ExpertsIs it possible to insert  rows inside a database using GridView Control  that has a combo box in a column. Combo Box displays the Value but inserts the underlying code. If this is possible i would very much appreciate if anyone can give me an example using BoundControlsThanks and Best RegardsManish    Hi Generally we use DetailsView or FormView to insert new record. If you persist to use GridView please post your current code so that we can discuss further.Sincerely,Allen ChenMicrosoft Online Community SupportPlease remember to mark the replies as answ...

How to add a blank row into GridView Control, for editing and inserting data into database.
Dear all:      I show my data in browser with ObjectDataSource and GridView .The GridView have Edit,Select,Update functions.However ,I have an idea that: if I click some button, the GridView Control can add one blank row in its bottom where I can Edit data and Insert these data into database.I don't know whether the GridView Control  have these function.      Please give me some advise.      Thanks a lot! The GridView don't support Insert. Take a look at th...

Is having a trigger that inserts a row in Table 'A', when a row in same table is inserted by ADo.Net code?
I want to insert a row for a Global user  in Table 'A' whenever ADO.Net code inserts a Local user row into same table. I recommended using a trigger to implement this functionality, but the DBA was against it, saying that stored proecedures should be used, since triggers are unreliable and slow down the system by placing unecessary locks on the table. Is this true OR the DBA is saying something wrong? My thinking is that Microsoft will never include triggers if they are unreliable and the DBA is just wanting to offload the extra DBA task of triggers to the programmer so that a s...

How to insert new row between the existing row in the gridview dynamically and how to insert value in it
hi,       I have a grid view i populate the grid with student records, i have a button called sub_Average when i click the button, the rows should reorder(groped) depend on department, and the average of each department should come under the end of each department (ie) a new row should be inserted for display Average of each department. Each new row should insert below the end of each department. Now my problem is i populate the records directly from dataset, so i dn't know how to insert a new row for average in the grid dynamically for each depar...

Selecting the multiple rows in GridView and inserting the selected rows to another Gridview & Performing some operations on it
 Dear All, I have become mad for solving this problem. Please Help me. I have a Gridview bound to a datasource. I inserted the CheckBox Control in Templet to select certain rows. Gridview1 contains some products id & name.I want to insert the selected rows in to second Gridview  and in the second Gridview I need to add two more colums AdvicedQty & AcceptedQty(TextBox Cotrol).The user will select few products in Gridview1 & clicks add which will be added another gridview then in second Gridview he enters the AdviceQty & AcceptedQty.After entering the data he cli...

Insert row above selected row in GridView
Hi, I've been asked to create a list with an insert button at the end of each row that, when clicked, will insert a new line above the selected row and allow the user to enter in information.  It won't be an edit, but a new entry - however it needs to be displayed above the row with the "Insert" button.  I'm not sure if this is possible or not, but any help would be most appreciated. Thanks! Check this article my suggestion helps Regards,Vinz"Code, Beer and Music" that's my way of ...

Howto: insert multiple rows of data from a gridview into a sql database
I have a gridview with rows of info which does not go into edit mode. A user clicks a checkbox which picks that item and adds a quantity which does some calculations. What i need to do is when a user clicks on a button, it should scan through the gridview for all items checked and pick up the quantity values and a couple of other field values and insert the information into a sql database What would be the best way of doing this? I tried the following example using a stored proc, but could not locate the proper reference or namespace for Database db = DatabaseFactory.CreateDatabase(); S...

Update other controls after a Postback has fired from another control - eg insert data
Hi This is a slight modification to the personalweb template which shipped with VS2005 I have a web form - linked to a master with two content placeholders left and right: #1 In the left i have a formview containing a textbox + button - and a datasrouce object with an insertmethod - this calls a method to insert the textbox data into table albums: #2 In the right  i have a gridview which has a datasource this has a selectmethod which calls a select method from table albums. Because i am using a maser template with two content placeholders i cannot use the same ObjectD...

Insert multiple rows of data from Gridview into SQL database
 Hi All, I have a grid view with rows of data from a database with elements of text box and a checkbox etc. I am using Itemtemplate to do this: <ItemTemplate>          <asp:TextBox ID="txtEstimateAmount" runat="server"></asp:TextBox>   <asp:CheckBox ID="CheckBox1" runat="server" Text="Agreed?" /> </ItemTemplate> When the user fills in data I want to save the relevant data to the database, but do not know what the most efficient way to do t...

Show inserted row in Gridview after inserting in Detailsview
I can't seem to figure out how to wire up a gridview to fire after inserting a row in a detailsview to show the inserted row.  I am using the Primary Key field as the selection criteria.  Can anyone help?  Thanks. Bind the Gridview again after you insert the new record in that same event.Please mark as ANSWER if it helps YOU!...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

Updating and binding control to other controls within the same row of a GridView
HiIn the EditTemplate of my GridView I show 2 DropDownLists. When the user selects the first dropdownlist, I need it to update the contents of the second dropdownlist. I have my Subs that do this fine when not inside the GridView, but what is the correct way to do it whilst they are in the GridView?This is my current attempt that returns the error 'Object reference not set to an instance of an object'. I presume its related to correctly targeting the DropDownList in question? This is my GridView:<asp:GridView ID="GridView1" runat="server"  &...

Web resources about - Data Controls insert rows into gridview then insert rows from gridview into SQL Table -

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

TERROR IN JAKARTA: 'Situation under control' after explosions, gunfire erupt in Indonesian capital
At least six people are dead, including three police officers, after several explosions at the Sarinah shopping mall in an apparent multi-site ...

Backburn approved in bid to control bushfire before blaze hit Wye River - HeraldSun Search Search
A BACKBURN was approved to try to control a bushfire in the days before it tore through more than 100 homes in Wye River on Christmas Day.

WA fires: threatening Jindalee blaze brought under control
A fire that was at one stage a threat to lives on homes in Jindalee on Thursday has been brought under control.

Grassfire near Leneva in Victoria's north-east now under control, fire authorities say
A grassfire burning near Leneva in Victoria's north-east is now under control, fire authorities say.

Publicis Said to Weigh Bid for Control of Cheil Worldwide
Publicis Groupe is weighing a bid for a controlling stake in Cheil Worldwide, people with knowledge of the matter said. The French company is ...

Playing around with BMW’s 7 Series gesture control user interface
We take a BMW 7 Series for a short drive to play with its gesture control. Video shot/edited by Jennifer Hahn. (video link) LAS VEGAS—Yesterday, ...

BMW recalls i8 for stability control problem
... , BMW , Safety , Coupe , Hybrid , Performance BMW will recall a small number of 2015 i8s because of a problem with the dynamic stability control ...

Embracing the NRA on gun control
I’m just stealing a massive post from Stonekettle Station on a plausible path forward towards sanity on guns: Those laws should be designed ...

Researchers say that Apple controls over 50% of the smartwatch market
Apple sold over half of all smartwatches in 2015, according to research firm Juniper . Android Wear, which is developed by Google, captured ...

Resources last updated: 1/15/2016 10:47:56 AM