How to display values in Dropdowncombo from a dataset or dataview object?

  • Thread starter Thread starter Vinitha
  • Start date Start date
V

Vinitha

I've given code like this ,
SqlConnection cnn = new qlConnection("initial talog=vin;uid=sa;pwd=;");
cnn.Open();
string strsql="select * from tblQualification";
SqlCommand cmd=new SqlCommand(strsql,cnn);
/// SqlDataReader rsreader=cmd.ExecuteReader();
SqlDataAdapter dadapt=new SqlDataAdapter();
dadapt.SelectCommand=cmd;
DataSet ds=new DataSet();
dadapt.Fill(ds,"tblA");
DataView dview=new DataView(ds.Tables["tblA"]);
DropDownList1.DataSource=dview;
DropDownList1.DataBind();

but the value displayed is "SYSTEM.DATAROW.DATAVIEW".

It will be helpful if some one could point me to some code sample for the
same

thank you in advance
 
Hi Vinitha,

Just add the following two lines before you do databind

for the drop-down list box.

DropDownList1.DataTextField="au_lname";
DropDownList1.DataValueField="au_id";

Hope this helps.

Cheers!!!

Nitin.
 
Try adding at the end
DropDownList1.DisplayMember=ds.Tables["tblAdd"].Columns[0].ColumnName;
DropDownList1.DisplayMember=ds.Tables["tblAdd"].Columns[1].ColumnName;

or choose yourself what should the user see and what should be the value of
the combo

Hope this helps

Dan Cimpoiesu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top