<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()
注意:将多个列值绑定到复选框列表。我需要将更多列值绑定到复选框列表。
我已经在使用DataTextField
和DataValueField
...
答案 0 :(得分:0)
您可以自定义SQL查询,以便它准确地提供您要显示的内容:
D.FillDataSet(DsStatus, "select AppStatusID, StatusDescription + ' - ' + SomeOtherField as CustomDescription from Z_AppStatusMaster")
ChkStatus.DataSource = DsStatus
ChkStatus.DataTextField = "CustomDescription"
ChkStatus.DataValueField = "AppStatusID"
答案 1 :(得分:0)
为此,您将需要创建一个从DropDownList继承的类,然后覆盖SaveViewState,LoadViewState和RenderContents子例程。
我无法发布我们的代码,因为它是专有的,但是我们先这样做,然后通过添加属性为每个项目添加其他值。例如:
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
本文将为您提供大部分帮助: http://www.techinfocorner.com/post/Adding-Attributes-and-Keeping-DropDownList-ListItems-Attributes-on-Post-back-in-ASPNET
此链接也应有所帮助:ListItems attributes in a DropDownList are lost on postback?