Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 780225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:02:30+00:00 2026-05-14T20:02:30+00:00

I haven’t used repeaters for much more than showing data from a datatable. I

  • 0

I haven’t used repeaters for much more than showing data from a datatable.

I am building a grid that that shows a list of users and columns of roles that the user has been assigned, shown with checkboxes (shown with true/false below but pretent they are checkboxes).

ex.

|Rep Name|Caller|Closer|Manager|SuperUser|
|Bob           |True  |true   | false      | false |
|Tom          |false  |false  |True       | True |

Basically using it for roles management.

However the roles may change later on so I want to load the roles(headers and items) dynamically into the repeater.

I am not sure how to do this or if it is even possible.

I figure you grab a list of current role possibilities and load them into the headertemplate but I am not sure how to match those with the itemtemplate and how to create checkboxes and place them in the itemtemplate.

Sorry if it is a rudementary question…. I appreciate any advice!

Datatable example of data that I am going to get… though I will also return ids for roles and users that are not shown here.

DataTable dt = new DataTable();
DataColumn dc = new DataColumn();

      dc.DataType = Type.GetType("System.String");
      dc.ColumnName = "RepName";
      dt.Columns.Add(dc);

      dc = new DataColumn(); 
      dc.DataType = Type.GetType("System.Boolean");
      dc.ColumnName = "Caller";
      dt.Columns.Add(dc);

      dc = new DataColumn();
      dc.DataType = Type.GetType("System.Boolean");
      dc.ColumnName = "closer";
      dt.Columns.Add(dc);

      dc = new DataColumn();
      dc.DataType = Type.GetType("System.Boolean");
      dc.ColumnName = "Admin";
      dt.Columns.Add(dc);

      dc = new DataColumn();
      dc.DataType = Type.GetType("System.Boolean");
      dc.ColumnName = "SuperUser";
      dt.Columns.Add(dc);


      DataRow row;

      row = dt.NewRow();

      row["RepName"] = "Joe";
      row["Caller"] = true;
      row["closer"] = false;
      row["Admin"] = true;
      row["SuperUser"] = false;
      dt.Rows.Add(row);

      row = dt.NewRow();

      row["RepName"] = "Bob";
      row["Caller"] = true;
      row["closer"] = false;
      row["Admin"] = true;
      row["SuperUser"] = false;
      dt.Rows.Add(row);


      row = dt.NewRow();

      row["RepName"] = "Tom";
      row["Caller"] = true;
      row["closer"] = false;
      row["Admin"] = true;
      row["SuperUser"] = false;
      dt.Rows.Add(row);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:02:30+00:00Added an answer on May 14, 2026 at 8:02 pm

    Use nested Repeaters: the outer Repeater is for rows and has a HeaderTemplate and ItemTemplate which contain inner Repeaters for header and checkbox columns respectively. Something like this:

    <asp:Repeater runat="server" ID="rowRepeater" OnItemDataBound="rowRepeater_ItemBound">
        <HeaderTemplate>
            <table>                                
            <tr>
                <asp:Repeater runat="server" ID="headerRepeater">
                    <ItemTemplate>
                        <th>
                            <%# Container.DataItem %>
                        </th>
                    </ItemTemplate>
                </asp:Repeater>
            </tr>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td><asp:Label runat="server" ID="lblUserName" Text='<%# Eval("Key") %>' /></td>
                <asp:Repeater runat="server" ID="columnRepeater">
                    <ItemTemplate>
                        <td>
                            <asp:HiddenField runat="server" ID="hfRoleIndex" Value='<%# Container.ItemIndex %>' />
                            <asp:CheckBox runat="server" ID="cbColumnValue" Checked='<%# Container.DataItem %>' OnCheckedChanged="cbColumnValue_CheckedChanged" AutoPostBack="true" />
                        </td>
                    </ItemTemplate>
                </asp:Repeater>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
    

    and in your code behind:

    Dictionary<string, bool[]> userRoles = new Dictionary<string, bool[]>(){
        {"Bob", new bool[]{true,true,false,false}},
        {"Tim",new bool[]{false,false,true,true}},
        {"John",new bool[]{false,true,false,true}}
    };
    
    string[] headings = { "Rep Name", "Caller", "Closer", "Manager", "SuperUser" };
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            rowRepeater.DataSource = userRoles;
            rowRepeater.DataBind();
        }
    }
    
    protected void rowRepeater_ItemBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Header)
        {
            Repeater headerRepeater = e.Item.FindControl("headerRepeater") as Repeater;
            headerRepeater.DataSource = headings;
            headerRepeater.DataBind();
        }
        else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater columnRepeater = e.Item.FindControl("columnRepeater") as Repeater;
            columnRepeater.DataSource = ((KeyValuePair<string, bool[]>)e.Item.DataItem).Value;
            columnRepeater.DataBind();
        }
    }
    
    protected void cbColumnValue_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox cb = sender as CheckBox;
        HiddenField hf = cb.Parent.FindControl("hfRoleIndex") as HiddenField;
        int roleIndex = int.Parse(hf.Value); // now you have the column identifier
    
        Label lbl = cb.Parent.Parent.Parent.FindControl("lblUserName") as Label;
        string userName = lbl.Text; //now you have the row identifier
    
        //now you can update your data source
        userRoles[userName][roleIndex] = cb.Checked;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haven't seen this feature anywhere else. I know that the 32nd bit is used
haven't used regex replaces much and am not sure if how I have done
I haven't done much coding in C++, but I? noticed that I have to
I haven't used C++ since college. Even though I've wanted to I haven't needed
I have text I am displaying in SIlverlight that is coming from a CMS
I haven't really done much on this side of project development so please forgive
I haven't used a png hack for IE6 for ages. Last time I used
I'm getting an error here that says I haven't defined a method, but it
I haven't quite got my head around R and how to rearrange data. I
Haven't fired up reflector to look at the difference but would one expect to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.