| | |
[B]DropDownList, TextBox to GridView.....[/B]
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 6
Reputation:
Solved Threads: 1
Hello Friends,
On my web form there is one DropDown List Box which contains different Items..
and one TextBox, user will Enter Quantity in textBox....
Now problem is that I want to Add Item and Qty in DataGrid on the Same Page when I click on ADD Button.........
Later on Data in DataGrid will go to DataBase when user Clicks on Send Button.....
So pls Help me....I will be Thankful to u...(A'm using Visual Studio 2005 and SQL Server 2005)
On my web form there is one DropDown List Box which contains different Items..
and one TextBox, user will Enter Quantity in textBox....
Now problem is that I want to Add Item and Qty in DataGrid on the Same Page when I click on ADD Button.........
Later on Data in DataGrid will go to DataBase when user Clicks on Send Button.....
So pls Help me....I will be Thankful to u...(A'm using Visual Studio 2005 and SQL Server 2005)
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
you can do such batch operations using table adapter, but you need to store the datatable in session i guess. So instead of adding to the database you can add to the datatable and at the end make a batch update to the database. But for the web applications this seems illogical. I suggest that you use update panel and run insert queries against database each time new record added.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Feb 2008
Posts: 30
Reputation:
Solved Threads: 4
hi mukund_007,
For doing the same you need to add Textbox, DropDownList and Button and datagrid to aspx page as follows.
<asp: TextBox ID ="txtBox" runat ="server"></asp: TextBox>
<asp: DropDownList ID="ddlist" runat ="server" >
<asp: ListItem Text ="1" Value ="1"></asp: ListItem>
<asp: ListItem Text ="2" Value ="2"></asp: ListItem>
<asp: ListItem Text ="3" Value ="3"></asp: ListItem>
<asp: ListItem Text ="4" Value ="4"></asp: ListItem>
</asp: DropDownList>
<asp: Button ID="submit" runat ="server" Text="submit" OnClick="submit_Click"/>
<asp: DataGrid ID="dgrid" runat ="server" ></asp: DataGrid>
You need to add your datagrid table to session["SampleDataTable"]; on page load.
Then on the Button click event you write as follows.
protected void submit_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable("ani");
dt = (DataTable)Session["SampleDataTable"];
if (dt == null)
{
dt.Columns.Add(new DataColumn("TextBox_Value", typeof(String)));
dt.Columns.Add(new DataColumn("Item_Name", typeof(String)));
}
DataRow dr = dt.NewRow();
dr[0] = txtBox.Text;
dr[1] = ddlist.SelectedValue;
dt.Rows.Add(dr);
dgrid.DataSource = dt;
dgrid.DataBind();
Session["SampleDataTable"] = dt;
}
After finishing of all the batch operation you need to update database to reflect the change in database.
Hope this will help you.
Thakns & Regards
Dilipv
For doing the same you need to add Textbox, DropDownList and Button and datagrid to aspx page as follows.
<asp: TextBox ID ="txtBox" runat ="server"></asp: TextBox>
<asp: DropDownList ID="ddlist" runat ="server" >
<asp: ListItem Text ="1" Value ="1"></asp: ListItem>
<asp: ListItem Text ="2" Value ="2"></asp: ListItem>
<asp: ListItem Text ="3" Value ="3"></asp: ListItem>
<asp: ListItem Text ="4" Value ="4"></asp: ListItem>
</asp: DropDownList>
<asp: Button ID="submit" runat ="server" Text="submit" OnClick="submit_Click"/>
<asp: DataGrid ID="dgrid" runat ="server" ></asp: DataGrid>
You need to add your datagrid table to session["SampleDataTable"]; on page load.
Then on the Button click event you write as follows.
protected void submit_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable("ani");
dt = (DataTable)Session["SampleDataTable"];
if (dt == null)
{
dt.Columns.Add(new DataColumn("TextBox_Value", typeof(String)));
dt.Columns.Add(new DataColumn("Item_Name", typeof(String)));
}
DataRow dr = dt.NewRow();
dr[0] = txtBox.Text;
dr[1] = ddlist.SelectedValue;
dt.Rows.Add(dr);
dgrid.DataSource = dt;
dgrid.DataBind();
Session["SampleDataTable"] = dt;
}
After finishing of all the batch operation you need to update database to reflect the change in database.
Hope this will help you.
Thakns & Regards
Dilipv
Last edited by dilipv; Feb 20th, 2008 at 4:57 am. Reason: spelling mistake
Dilip Kumar Vishwakarma
Programmer
.Net Consulting
If this post is answer for your query then don't forget to mark as an answer.
Programmer
.Net Consulting
If this post is answer for your query then don't forget to mark as an answer.
![]() |
Similar Threads
- need code for updating gridview without using sql datasource (C#)
- GridView cell textbox.Visible = true (ASP.NET)
- Dynamically add rows in datagrid (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Passing a variable to another page
- Next Thread: Populate DropDown List from Sql Database
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos application asp asp.net bc30451 bottomasp.net box browser button c# c#gridviewcolumn checkbox click commonfunctions confirmationcodegeneration css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fileuploader fill flash form formatdecimal forms formview grid gridview gudi homeedition hosting iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security select silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos view virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers






