943,822 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 6086
  • ASP.NET RSS
Feb 20th, 2008
0

[B]DropDownList, TextBox to GridView.....[/B]

Expand Post »
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)
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
mukund_007 is offline Offline
6 posts
since Feb 2008
Feb 20th, 2008
0

Re: [B]DropDownList, TextBox to GridView.....[/B]

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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Feb 20th, 2008
0

Re: [B]DropDownList, TextBox to GridView.....[/B]

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
Last edited by dilipv; Feb 20th, 2008 at 4:57 am. Reason: spelling mistake
Reputation Points: 10
Solved Threads: 4
Light Poster
dilipv is offline Offline
30 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Passing a variable to another page
Next Thread in ASP.NET Forum Timeline: How do you search all current sessions on the sever, or within the website?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC