0

The following is my code to show One Title followed by one checkboxlist.

Markup:

<asp:Repeater id="repRoles" runat="server">
       <ItemTemplate>
              <asp:literal runat="server" text=<%# DataBinder.Eval(Container.DataItem, "ItemTitle") %>></asp:literal>
              <br />
              <asp:CheckBoxList runat="server" DataSourceID=<%# FillinCbl(DataBinder.Eval(Container.DataItem,"ItemID").ToString()) %> 
                                    DataTextField="ItemName" DataValueField="ItemValue">
              </asp:CheckBoxList>
       </ItemTemplate>
</asp:Repeater>

Code behind:

private void FillinRepeater()
{
    try
    {
        List<Item> targetAudienceParent = new List<Item>();
        DataTable tempTbl = new DataTable();
        tempTbl.Columns.Add("ItemTitle", typeof(String));
        tempTbl.Columns.Add("ItemID", typeof(String));
        DataRow tempRow;
        int tempCount = 0;
        foreach (Item a in itmECM.Children)
        {
            try
            {
                tempRow = tempTbl.NewRow();
                tempRow["ItemTitle"] = a.Name.ToString();
                tempRow["ItemID"] = a.ID.ToString();
                tempTbl.Rows.Add(tempRow);
                tempCount++;
            }
            catch
            {
            }
        }
        repRoles.DataSource = tempTbl;
        repRoles.DataBind();
    }
    catch
    {
    }
}
public DataTable FillinCbl(String passedString)
{
    dtlRoles = new DataTable();
    dtlRoles.Columns.Add("Name", typeof(String));
    dtlRoles.Columns.Add("OptInID", typeof(String));
    dtlRoles.Columns.Add("OptOutID", typeof(String));
    Item tempItm = master.GetItem(passedString);
    DataTable tempTbl = new DataTable();
    tempTbl.Columns.Add("ItemName", typeof(String));
    tempTbl.Columns.Add("ItemValue", typeof(String));
    DataRow tempRow;
    try
    {
        populateUsersList(tempItm);
        Session["dtlRoles"] = dtlRoles;
        for (int a = 0; a < dtlRoles.Rows.Count; a++)
        {
            try
            {
                Response.Write(dtlRoles.Rows[a][0].ToString().Trim() + "<br/>");
                tempRow = tempTbl.NewRow();
                tempRow["ItemName"] = dtlRoles.Rows[a][0].ToString().Trim();
                tempRow["ItemValue"] = dtlRoles.Rows[a][1].ToString().Trim();
                tempTbl.Rows.Add(tempRow);
            }
            catch(Exception ex1)
            {
                Response.Write(ex1.ToString() + "<br/>");
            }
        }
    }
    catch (Exception ex2)
    {
        Response.Write(ex2.ToString() + "<br/>");
    }
    return tempTbl;
}

The problem is only the literal is showing. The checkboxlist is not filled in.

When I response.write() for my DataBind method for checobxlist they are out.

So my code behind is working. There is something missing though. But I can't find out what.

1
  • Kind of. I have tested that the DataSource method is calling FillInCbl and the DataTable is filled with the values. It is just not binding to the checkboxlist Commented Jul 3, 2012 at 10:39

1 Answer 1

1

Change DataSourceID to DataSource

<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSource=<%# FillinCbl(DataBinder.Eval(Container.DataItem,"ItemID").ToString()) %>  DataTextField="ItemName" DataValueField="ItemValue">
Sign up to request clarification or add additional context in comments.

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.