AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
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
student:c_id,sec_id,roll_no,s_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
Hi,

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">
</asp:DropDownList>
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
Building a Web Application Security Program
Simply SQL - Free 111 Page Preview!
Introduction to Web Applications Development