0
<asp:Panel ID="plOffice" runat="server" ScrollBars="Vertical" Width="200px" Height="80px" CssClass="TB">
    <asp:CheckBoxList ID="chkOffice" runat="server" AppendDataBoundItems="True" Height="80px" AutoPostBack="True" OnSelectedIndexChanged="chkOffice_SelectedIndexChanged">
        <asp:ListItem>All</asp:ListItem>
    </asp:CheckBoxList>
</asp:Panel>
Dim DsStatus As New DataSet
D.FillDataSet(DsStatus, "select * from Z_AppStatusMaster")
ChkStatus.DataSource = DsStatus
ChkStatus.DataTextField = "StatusDescription"
ChkStatus.DataValueField = "AppStatusID"
ChkStatus.DataBind()

Note: Bind multiple column values to checkboxlist. I need to bind more column values to checkboxlist. I am already using DataTextField and DataValueField...

barbsan
  • 3,418
  • 11
  • 21
  • 28
Rocky
  • 19
  • 4
  • Loop the items in the dataset and add `ListItems` manually. – VDWWD Jan 08 '19 at 09:19
  • I want to bind more column values from my database. I alerady used DataTextField,DataValueField.do you know other property that can store another column value? – Rocky Jan 08 '19 at 09:23
  • `ChkStatus.Items.Add(new ListItem() { Text = A + B, Value = A + B });` – VDWWD Jan 08 '19 at 09:38

2 Answers2

0

You can customize the SQL Query so it delivers exactly what you want to display:

D.FillDataSet(DsStatus, "select AppStatusID, StatusDescription + ' - ' + SomeOtherField as CustomDescription from Z_AppStatusMaster")
ChkStatus.DataSource = DsStatus
ChkStatus.DataTextField = "CustomDescription"
ChkStatus.DataValueField = "AppStatusID"
Peter B
  • 22,460
  • 5
  • 32
  • 69
0

In order to do this you will need to create a class that inherits from the DropDownList and then overrides the SaveViewState, LoadViewState and RenderContents subroutines.

I cannot post our code as it is proprietary, but we do this and then add additional values to each item by adding an attribute. As an example:

   For Each dr In ds.Tables(1).Rows
        cbo.Items.Add(New System.Web.UI.WebControls.ListItem(dr("NAME"), dr("VALUE")))

        cbo.Items(cbo.Items.Count - 1).Attributes.Add("GROUP", dr("GROUP"))

    Next

This article will get you most of the way there: http://www.techinfocorner.com/post/Adding-Attributes-and-Keeping-DropDownList-ListItems-Attributes-on-Post-back-in-ASPNET

And this link should help as well: ListItems attributes in a DropDownList are lost on postback?

JMabee
  • 2,230
  • 2
  • 9
  • 13