Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have to enable certain buttons and textboxes on selecting a dropdownlist item.
I fetch the drop down list items from database through a query.
How a If loop will work in this case if i have to select an item from dropdownlist ??
Kindly help
thanks
Posted

Use this code

DataTable datatable = logic.GetID();
if (datatable != null)
{
if (datatable.Rows.Count > 0)
{
ddlTeacherID.DataSource = datatable;
ddlTeacherID.DataValueField = datatable.Columns[0].ToString();
ddlTeacherID.DataTextField = datatable.Columns[0].ToString();
ddlTeacherID.DataBind();

}
}


Hare GetID() method contains your query
 
Share this answer
 
C#
private void Fillddl()
    {
        DataTable dtNames = new DataTable();
        dtNames = GetNames();
        if (dtNames != null)
        {
            ddlid.DataSource = dtNames ;
            ddlid.DataTextField = "NAME";
            ddlid.DataValueField = "ROLL_NO";
            ddlid.DataBind();
        }
        ddlid.Items.Insert(0, "Select");
        ddlid.Items[0].Value = "-1";
    }

In GetNames()
Get datatable with two columns NAME and ROLL_NO
Using any of database query
IF it returns
VB
NAME      ROLL_NO
-----------------
Manoj     456456
Roshan    789456

Ur Drop down will contain

Select
Manoj
roshan

with value respective roll number
 
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