vijay krish

vijay krish

  • NA
  • 13
  • 27.4k

how to populate dropdownlist value from database value

Dec 5 2012 7:36 AM
hi,in my code i have one requirement....in my form ,i have textboxes and dropdownlists and radiobutton list...i have two buttons save & Get...if i click on save button the values in the textboxes and dropdownlist values are saved to database...it's working..bt when i click on Get
button,the values in the database come and sit in the respective textboxes and drpdownlists...
text boxes are working bt how to come and sit database values into dropdownlist....i used datareader to capture the database values...i have a drpdownlist containing items like
mr.,
mrs.,
baby,
master
i select baby and click on save button data saved to pat_honor column..
how to retreive that value and assign it to same drpdown when click on Get button...how the value baby come and sit in that dropdownlist...i have taken one datareader to capture that values...i have written the code like
string getstr = "select Pat_Honor,Pat_First,Pat_Last,Pat_Sex from PAT_MAST where Pat_Id=@Pat_Id";
            cmd.CommandText = getstr;
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@Pat_Id", TextBox3.Text);
            dr = cmd.ExecuteReader();
 DropDownList3.DataSource = dr;
               DropDownList3.DataTextField = "Pat_Honor";
               DropDownList3.DataValueField = "Pat_Honor";
                DropDownList3.DataBind();
but it is not working for dropdownlists...
dropdownlist is bcoming empty...
plz tell me the solution..
thanx in advance

Answers (1)