Hello there, I'm still new at performing miracles with code
. 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.
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.'
![]() |
0 |
![]() |
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.
![]() |
0 |
![]() |
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?
+
Lvl FIVE THOUSAND DRAGON MASTER SOFTWARE ENGINEER
my friends call me MOI
![]() |
0 |
![]() |
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?
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.'
![]() |
0 |
![]() |
onrow command if(command.name ==update)
{
SqlDataSource.updateparameter["CreatedById"].DefaultValue = gridview.rows[gridview.editrowindex].findcontrol("ddlBusGroup").SelectedValue.ToString();
}try something like that? is that what youre asking?
+
Lvl FIVE THOUSAND DRAGON MASTER SOFTWARE ENGINEER
my friends call me MOI
![]() |
0 |
![]() |
Hi
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" TypeName="DSTasksWorkedTableAdapters.TasksWorkedTableAdapter" UpdateMethod="Update">and I have used this for the insert parameters...
<InsertParameters> <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..
![]() |
1 |
![]() |
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
http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx
http://aspalliance.com/1125_Dynamically_Templated_GridView_with_Edit_Delete_and_Insert_Options
the second one uses templatefields, i would suggest learning these and not being scared of them. THEY KICK A$$ A(dollars)
+
Lvl FIVE THOUSAND DRAGON MASTER SOFTWARE ENGINEER
my friends call me MOI
![]() |
0 |
![]() |
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 ");conn.Open();
string sql = "insert into TasksWorked (PrimaryTask,Classifications,ProjectName,TaskComments) values (@PrimaryTask,@Classifications,@ProjectName,@TaskComments)";SqlCommand cmd = new SqlCommand(sql, conn);cmd.ControlParameters.Add(@PrimaryTask
"???????,cmd.ExecuteNonQuery();
conn.Close();
}
![]() |
0 |
![]() |
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);
cmd.controlparamaters.add(param);
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......
+
Lvl FIVE THOUSAND DRAGON MASTER SOFTWARE ENGINEER
my friends call me MOI
![]() |
0 |
![]() |