Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET HTML
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 27-Nov-12 0:35am
Ash29470
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
NAME      ROLL_NO
-----------------
Manoj     456456
Roshan    789456
Ur Drop down will contain
 
Select
Manoj
roshan
 
with value respective roll number
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100