SelectionList DataValueField problem

B

Brad Wist

I've got a set of code that is attempting to build a SelectionList. The
values are not sequential. I bind the control to a dataset in which the
values being passed are correct. But the values that are entered into the
selectionlist are simple sequential indexes.

Am I missing something here? Or is this a bug in data binding with the
SelectionList?

Here's the code:


daUnits.Fill(dsMyList);

selUnit.DataSource = dsUnitList;

selUnit.DataTextField = "sName";

selUnit.DataValueField = "Id";

selUnit.DataBind();



And here is an excerpt of the source data

<dbo_spListUnit>
<Id>58</Id>
<sCode>Unit1 </sCode>
<sName>First Unit</sName>
</dbo_spListUnit>
<dbo_spListUnit>
<Id>230</Id>
<sCode>UnitC </sCode>
<sName>Second Unit</sName>
</dbo_spListUnit>
<dbo_spListUnit>
<Id>119</Id>
<sCode>UnitX </sCode>
<sName>Third Unit</sName>
</dbo_spListUnit>

The name appears fine in the list, but the values are consistently 0, 1, 2,
etc... sequential through the list, and do not include the "id" value from
the source data.

Thanks.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top