Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NETHTML
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
Ash29465
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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 529
1 OriginalGriff 307
2 Damith Weerasinghe 295
3 ravikhoda 260
4 Tadit Dash 180
0 Sergey Alexandrovich Kryukov 10,974
1 OriginalGriff 6,667
2 Peter Leow 4,760
3 Abhinav S 3,813
4 Maciej Los 3,565


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