Put the checkboxlist control on to aspx page as follows:
- <asp:CheckBoxList ID="checkboxlist1" AutoPostBack="True"
- RepeatDirection="Horizontal" TextAlign="Right" runat="server"
- RepeatColumns = 5 ondatabound="checkboxlist1_DataBound">
- </asp:CheckBoxList>
Bind the checkboklist control on codebehind as follows:
- private void FillIcons()
- {
-
- if (datatable.Rows.Count > 0)
- {
- checkboxlist1.DataSource = datatable;
- checkboxlist1.DataTextField = "ImageName";
- checkboxlist1.DataValueField = "Name";
- checkboxlist1.DataBind();
- }
- }
Add these lines for displaying the image.
- protected void checkboxlist1_DataBound(object sender, EventArgs e)
- {
- foreach (ListItem item in checkboxlist1.Items)
- {
- item.Text = string.Format("<img src= \"{0}\" title='" + item.Value + "'/>",
- string.Format("images/{0}", item.Text), null);
- }
- }