0

I have asp:datalist binding from table this table contain two columns one of them string and the other is list<string>

I am binding the string value in <div> and I want to bind the list<string> in asp:CheckBoxList How Can I do this in html or .cs ?

this is html part

<asp:DataList ID="feedbacklist" RepeatDirection="Vertical" runat="server" Width="100%">
        <ItemTemplate>
            <div class="rowstyle2" style="width: auto">
                    <%# Eval("Question")%>
            </div>
            <div class="news_des">
             <asp:CheckBoxList ID="answerslist" runat="server" RepeatDirection="Horizontal" Width="100px">
             </asp:CheckBoxList>
            </div>
        </ItemTemplate>
    </asp:DataList>

this is c# part in page load

List<string> boollist = new List<string>();
        List<string> stringlist = new List<string>();
        boollist.Add("Yes");
        boollist.Add("No");
        stringlist.Add("1");
        stringlist.Add("2");
        stringlist.Add("3");
        DataTable test = new DataTable();
        test.Columns.Add("Question", typeof(string));
        test.Columns.Add("Answers", typeof(List<string>));
        test.Rows.Add("What do you think of our new website?", boollist);
        test.Rows.Add("What do you think so?", stringlist);
        feedbacklist.DataSource = test;
        feedbacklist.DataBind();

2 Answers 2

2

Three things you may wish to look at:

  1. Use a BindingList
  2. Add a BindableAttribute to your Name property
  3. Binding to a CheckListBox Binding DropDownList, ListBox and CheckBoxList Control the ADO.NET way
Sign up to request clarification or add additional context in comments.

Comments

0
<asp:DataList ID="feedbacklist" RepeatDirection="Vertical" runat="server" Width="100%">
                <ItemTemplate>
                    <div class="rowstyle2" style="width: auto">
                            <%# Eval("Question")%>
                    </div>
                    <div class="news_des">
                     <asp:RadioButtonList ID="answerslist" runat="server" RepeatDirection="Horizontal" DataSource='<%# Eval("Answers")%>'>
                     </asp:RadioButtonList>
                    </div>
                </ItemTemplate>
            </asp:DataList>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.