<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
...
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"
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.