¿Cómo vincular la lista desplegable a un conjunto de datos escrito en C#?

I have added a dataset(xsd) to my web application and cofigured it to SQL database and wrote a select query and named it as Getdata(). if i open the xsd file it has Getdata() method in it under TableAdapters. Dataset(xsd) TableAdapter has Getdata() method to get the details.How to call this method of TableAdapter of xsd in C# and bind the data to dropdownlist.please suggest me the complete C# code to do this.

preguntado el 04 de julio de 12 a las 05:07

Get the DataTable. Bind the DataTable. What's "not working"? -

You'd better put some your code here. It would help others to solve your issue. -

2 Respuestas

Puedes hacerlo así.

YourTableAdapter  yourTableAdapter = new YourTableAdapter();
YourTypedDataSetClass.YourTableDataTable yourTable = yourTableAdapter .GetData();
dropdownlist1.DataTextField = "TextFieldInYourTable";
dropdownlist1.DataValueField = "ValueFieldInYourTable";
dropdownlist1.DataSource = yourTable;
dropdownlist1.DataBind(); 

Respondido 04 Jul 12, 08:07

He used typed datasets, not LINQ. - kirin yao

Linq could be used to query data from typed dataset and it makes it easy. Please read this msdn.microsoft.com/en-us/library/bb399358.aspx - Adil

Of course he can use LINQ to DataSet, but there is no any XxxDataContext class to make use of. You should edit your answer. BTW, I'm not the one down voting your answer. - kirin yao

puedes probar con este codigo

TypedDataSet typedDataSet  = ....;
dropdownlist1.DataTextField = typedDataSet.YourTable.YourColumn1;
dropdownlist1.DataValueField = typedDataSet.YourTable.YourColumn2;
dropdownlist1.DataSource = typedDataSet;
dropdownlist1.DataBind();

Respondido 04 Jul 12, 08:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.