Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 Insert id in place of name into database
Posted by sanjay on  3/1/2010 7:46:30 AM Category: C#
Add to my favorites
Email to friend
In my database application, there are three tables:
class : c_id , c_name
section: c_name,sec_id,sec_name

There are 2 comboboxes: One for selecting class name and other for selecting section name .
Now I want to add enteries to student table, such that :
(i) I select class name from combo1 but corresponding c_id should be inserted in student table.
(ii)I select section name from combo2 , but corresponding sec_id should be inserted in student table.
(iii) roll_no and s_name are added through texboxes on the form .

Post Your Reply Post New Question

 Viewer's Reply
Set DataValueField and DataTextField in DropDownlist control
Answered By Moderator1 on 3/5/2010 8:04:42 PM

Before you bind the Class DropDownList control set the DataValueField as "C_Id" and DataTextField as "C_Name". Do the same for Section. Below I give sample of section dropdownlist control.
<asp:dropdownlist ID="ddlSection" runat="server" DataTextField="Sec_Name" DataValueField="Sec_Id">
You can access the value of Sec_Id from the code behind as ddlSection.SelectedValue.
So take the SelectedValue of both dropdown control and insert into the Student Table.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
Take Advantage of Oracle's 2 Day DBA Course
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
Many .NET teams are underperforming, is yours?