1

I have a CheckBoxList that I want to populate using a collection of ListItems with Text and Values defined.

var temp = types.Select(x => new ListItem(x["Description"].ToString(), x["TypeCode"].ToString()));
chbox.DataSource = temp;
chbox.DataBind();

The ListItems in temp have the correct Text and Value property values, but after chbox.DataBind(), all of the Value properties are populated with the Text property value.

So if the ListItems in temp look like

Text    Value
LetterA A
LetterB B

The ListItems in chbox.Items look like

Text    Value
LetterA LetterA
LetterB LetterB

1 Answer 1

3

You may want to define

 DataTextField="TextField" DataValueField="ValueField"

as shown below:

 <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataTextField="TextField" DataValueField="ValueField">
        </asp:CheckBoxList>

Please check out DataTextField and DataValueField

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.