Reputation: 25
I'm trying to use checkbox list in repeater at asp.net, C#.
But NO "CHOICES_CONTENT" comes up on web page..
Here's my code.
<asp:Repeater id="Repeater0"runat="server"DataSource='<%#GetChild(Container.DataItem,"ChoicesRelate") %>'>
<ItemTemplate>
<asp:CheckBoxList ID="chkBoxListGoup" runat="server"
DataTextField="CHOICES_CONTENT"
DataValueField="CHOICES_CONTENT">
</asp:CheckBoxList>
</ItemTemplate>
</asp:Repeater>
Where should I modify?
I've changed my code a little bit.
<asp:Repeater id="Repeater1" runat="server" DataSource='<%# GetChild(Container.DataItem,"ChoicesRelate") %>'>
<ItemTemplate>
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Value=""> CHOICES_NO </asp:ListItem>
<asp:ListItem Value="CHOICES_ID" Text='<%# Eval("QUESTION_CONTENT") %>'> </asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:Repeater>
Next problem is that I can't use Eval("QUESTION_CONTENT") in asp tag. How can I pick up "QUESTION_CONTENT" data??
Upvotes: 2
Views: 2197
Reputation: 721
Use repeater OnItemDataBound event.
<asp:Repeater ID="rptTest" runat="server" OnItemDataBound="rptTest_ItemDataBound">
<ItemTemplate>
<asp:CheckBoxList ID="ChkBoxList" runat="server">
</asp:CheckBoxList>
</ItemTemplate>
</asp:Repeater>
protected void rptTest_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType.Equals(ListItemType.AlternatingItem) || e.Item.ItemType.Equals(ListItemType.Item))
{
CheckBoxList cboxlist = e.Item.FindControl("chChkBoxListk") as CheckBoxList;
cboxlist.DataSource = "Datasource for checkbox list (datatable, object list and so on..)";
cboxlist.DataTextField = "TextDisplayField";
cboxlist.DataValueField = "ValueField";
cboxlist.DataBind();
}
}
Upvotes: 3