Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello i need some favor or may some solution to solve my problem. how to retrieve id from dropdownlist and when i click add button, the add page will save the data based on selected id from dropdownlist..? eg dropdownlist
C#
<asp:DropDownList ID="question1" runat="server" SelectedValue='<%#Eval ("q1") %>'>
<asp:ListItem Text="Medium" Value="M" />
<asp:ListItem Text="Easy" Value="A" />
</asp:DropDownList>


when i select easy, Add button will available to add and directly response to Add.aspx page and save the entered data based on easy id..?
Posted
Updated 17-Sep-12 21:05pm
v2
Comments
Herman<T>.Instance 18-Sep-12 3:08am    
what do you want exactly?
uti123fil 18-Sep-12 3:18am    
what i want is when i select the list item which is i already 'unbound' it from database, and click Add button, fill the form from page addregistration.aspx(eg) and the data will save using id from dropdownlist items
[no name] 18-Sep-12 3:09am    
is their selectedvalue property for drop downlist???
usually, we can get selected list items, text and value associated with it, like

question1.selectedvalue
question1.selecteditem.text
CodeHawkz 18-Sep-12 3:24am    
Of course there is :) Go to the link below, search for 'SelectedIndex', 'SelectedValue' and 'SelectedItem'. Play with these properties and you'll figure it out
http://msdn.microsoft.com/en-us/library/e0ybx34e.aspx

Good luck :)
uti123fil 18-Sep-12 3:29am    
thank you..(=

1 solution

Here is the code..Hope it will help you..

C#
string sqlQuery = "Select " + colName + ",0 as " + colValue + " Union Select " + colName + "," + colValue + " from " + tblName;
            if (srchCodn != "")
            {
                sqlQuery += " " + srchCodn;
            }
            adp = new SqlDataAdapter(sqlQuery, conn);
            tbl = new DataTable();
            adp.Fill(tbl);
            ddlList.DataSource = tbl;
            ddlList.DataTextField = colName;
            ddlList.DataValueField = colValue;
            ddlList.DataBind();


After Binding ddlList you can get the value using ddlList.DataValueField.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900