Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 C# DataSet member into Items collection

Author  Topic 

Sitka
Aged Yak Warrior

571 Posts

Posted - 2003-08-07 : 08:03:37
Generally or examples.
I found a searched ASP.NET Combobox free version (http://coreyhulen.com)
The code for these is way beyond my ability so I'll try and use this one.
On Page_Load I can't seem to get the .DataBind() to work as it does
with a standard DropDownList. The author has given some examples of populating the control, one sets each Item individually....

Combobox1.Items.Add(new ListItem("xxxxx", "yyyyyy"))

and the other set binds to some predefined objects within his distribution.

Combobox1.DataSource = coreyhulen.web.webcontrols.State.States;

The second method showed promise but dosen't behave exactly as VS.NET
would normally.

So what I need to do is utilize a foreach loop to mimic the Items.Add
technique to populate these controls. This would be great because the control lists don't change much and it makes sense to keep them client side, going to the server just once to fill the DataSet with a few members that can be manually refilled if needed.

This is where things get overwhelming because the DataSet member 'row' access methods or indexing is automated and takes a leap of understanding.
The automation uses the Container object a believe.
As a newb it is like the first time you see ADODB.Command short form parameter assignment. Lots going on. So any direction or examples would be helpful. I'm aware there are a few million of them out there already, just askin'.

This works

foreach (DataRow row in dataSet11.Table1.Rows)
{
Combobox1.Items.Add(new ListItem(row[0].ToString(),row[1].ToString()));
}


Or the general form:


foreach (DataTable table in myData.Tables) {
foreach (DataRow row in table.Rows) {
foreach (DataColumn col in table.Columns) {
Response.Write (row[col].ToString());
}
}
}

Stupid easy to use. Figured it out by reading a couple of pages on the IEnumerable interface



   

- Advertisement -