locked
DropDownList Which Binds Values from DB RRS feed

  • Question

  • User-2027411970 posted

    Hi All, 

    I want to develop a custom asp.net server control. A drop down list which contains values from Database table. 

    LIke EmpDropDownList contains Employees Names into Text and ID into Value field. 

    How to Develop it?

     

    Thanks in Advance. 

    Tuesday, April 28, 2009 7:24 AM

Answers

All replies

  • User-1814013008 posted

    Create one Custom Control which contains properties like ConnectionString, DataValueFiled, DataTextFiled, and TableName.

    Bind them in CustomControlLoad event, that will do...

    make sure that you are taking care of SelectedValues in post back..

    thank you,

    -nm reddy

    Tuesday, April 28, 2009 7:32 AM
  • User-1252661541 posted
    cmd = new SqlCommand(commandText, conn); cmd.Connection.Open(); dr = cmd.ExecuteReader(); //Bind Priority DropDownList.DataSource = dr; DropDownList.DataTextField = "Name"; DropDownList.DataValueField = "id"; DropDownList.DataBind(); Try This it will work
    Tuesday, April 28, 2009 7:32 AM
  • User-1253086575 posted

     u just need to bind data to dropdown list...

    cmd= new sqlcommand("select * from mydatabse",cn)

    dropdownlist1.datsource=cmd.executereader

    dropdownlist1.datbind();

     

     

    Tuesday, April 28, 2009 7:51 AM
  • User1306565749 posted

    Hi

    http://msdn.microsoft.com/en-us/library/aa479311.aspx

    http://forums.asp.net/t/946824.aspx

    Please mark this as Answer, if it helped

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2009 8:47 AM