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 8999523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:29+00:00 2026-06-16T00:11:29+00:00

I have a dynamically created Checkboxlist ( I am using Dynamic Data and I

  • 0

I have a dynamically created Checkboxlist ( I am using Dynamic Data and I am talking about the Many-to-many_edit.aspx ).
I have like 20 000+ item added in my Checkboxlist and I need pagination for this.

I thought binding this checkboxlist to a gridview would do the trick? How can I do this ?

EDIT: I’ve read a lot about this subject but I couldn’t find anything good . When I try to put Checkboxlist's source in my GridView.DatSource it throws OutOfMemory exception

EDIT2: I am trying something like this, but now, because my checkboxlist it’s inside the gridview I don’t know how to populate it anymore

code sample:

asp:GridView ID="GridView1" runat="server">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
      <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="3" OnDataBound="CheckBoxList1_DataBound" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

EDIT3:

My code aspx.cs

  public partial class ManyToMany_EditField :  System.Web.DynamicData.FieldTemplateUserControl
  {

 public void Page_Load(object sender, EventArgs e)

   {
    // Register for the DataSource's updating event
    EntityDataSource ds = (EntityDataSource)this.FindDataSourceControl();

    // This field template is used both for Editing and Inserting
    ds.Updating += new EventHandler<EntityDataSourceChangingEventArgs>(DataSource_UpdatingOrInserting);
    ds.Inserting += new EventHandler<EntityDataSourceChangingEventArgs>(DataSource_UpdatingOrInserting);


}

private void DataSource_UpdatingOrInserting(object sender, EntityDataSourceChangingEventArgs e)
{
    MetaTable childTable = ChildrenColumn.ChildTable;

    // Comments assume employee/territory for illustration, but the code is generic

    // Get the collection of territories for this employee
    RelatedEnd entityCollection = (RelatedEnd)Column.EntityTypeProperty.GetValue(e.Entity, null);

    // In Edit mode, make sure it's loaded (doesn't make sense in Insert mode)
    if (Mode == DataBoundControlMode.Edit && !entityCollection.IsLoaded)
    {
        entityCollection.Load();
    }

    // Get an IList from it (i.e. the list of territories for the current employee)
    // REVIEW: we should be using EntityCollection directly, but EF doesn't have a
    // non generic type for it. They will add this in vnext
    IList entityList = ((IListSource)entityCollection).GetList();

    // Go through all the territories (not just those for this employee)
    foreach (object childEntity in childTable.GetQuery(e.Context))
    {

        // Check if the employee currently has this territory
        bool isCurrentlyInList = entityList.Contains(childEntity);

        // Find the checkbox for this territory, which gives us the new state
        string pkString = childTable.GetPrimaryKeyString(childEntity);
        ListItem listItem = CheckBoxList1.Items.FindByValue(pkString);
        if (listItem == null)
            continue;

        // If the states differs, make the appropriate add/remove change
        if (listItem.Selected)
        {
            if (!isCurrentlyInList)
                entityList.Add(childEntity);
        }
        else
        {
            if (isCurrentlyInList)
                entityList.Remove(childEntity);
        }
    }
}

protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
    MetaTable childTable = ChildrenColumn.ChildTable;
    var a = childTable.CreateContext();
    var dataSource = childTable.GetQuery().AsQueryable();
    var Context = new testEntities();
    var daZtaSource = Context.GetType();

    GridView1.DataSource = dataSource;

    // Comments assume employee/territory for illustration, but the code is generic

    IList entityList = null;
    ObjectContext objectContext = null;

    if (Mode == DataBoundControlMode.Edit)
    {
        object entity;
        ICustomTypeDescriptor rowDescriptor = Row as ICustomTypeDescriptor;
        if (rowDescriptor != null)
        {
            // Get the real entity from the wrapper
            entity = rowDescriptor.GetPropertyOwner(null);
        }
        else
        {
            entity = Row;
        }

        // Get the collection of territories for this employee and make sure it's loaded
        RelatedEnd entityCollection = Column.EntityTypeProperty.GetValue(entity, null) as RelatedEnd;
        if (entityCollection == null)
        {
            throw new InvalidOperationException(String.Format("The ManyToMany template does not support the collection type of the '{0}' column on the '{1}' table.", Column.Name, Table.Name));
        }
        if (!entityCollection.IsLoaded)
        {
            entityCollection.Load();
        }

        // Get an IList from it (i.e. the list of territories for the current employee)
        // REVIEW: we should be using EntityCollection directly, but EF doesn't have a
        // non generic type for it. They will add this in vnext

        entityList =((IListSource)entityCollection).GetList();


        // Get the current ObjectContext
        // REVIEW: this is quite a dirty way of doing this. Look for better alternative
        ObjectQuery objectQuery = (ObjectQuery)entityCollection.GetType().GetMethod(
            "CreateSourceQuery").Invoke(entityCollection, null);
        objectContext = objectQuery.Context;
    }

    // Go through all the territories (not just those for this employee)
   foreach (object childEntity in childTable.GetQuery(objectContext))
    {
        MetaTable actualTable = MetaTable.GetTable(childEntity.GetType());
        // Create a checkbox for it
        ListItem listItem = new ListItem(
            actualTable.GetDisplayString(childEntity),
            actualTable.GetPrimaryKeyString(childEntity));

        // Make it selected if the current employee has that territory
        if (Mode == DataBoundControlMode.Edit)
        {
            listItem.Selected = entityList.Contains(childEntity);
        }

        CheckBoxList1.Items.Add(listItem);
    }

}

public override Control DataControl
{
    get
    {
        return CheckBoxList1;
    }
}

}

My code: Aspx

  <%@ Control Language="C#" CodeFile="ManyToMany_Edit.ascx.cs" Inherits="ManyToMany_EditField" %>

<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="3" OnDataBound="CheckBoxList1_DataBound" />
  • 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-06-16T00:11:30+00:00Added an answer on June 16, 2026 at 12:11 am

    Why do you want a checkbox list inside a gridview ? I think you may replace your checkboxlist by a checkbox and add a column with the data you want to display.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" showheader="false" allowpaging="true">
        <Columns>
        <asp:TemplateField>
        <ItemTemplate>
          <asp:CheckBox ID="CheckBoxList1" runat="server" checked='<%# Eval("myColumn")%>'/>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="cbxLabel" />
        </Columns>
        </asp:GridView>
    

    You will have the pagination that you are wanting.

    And also don’t forget during the page changing to save the checked checkboxes and to restore it also.

    To Paginate your result please take a look at this thread:
    How to paginate a gridview and SQL custom query with ROW_NUMBER

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning ASP.Net. I have a dynamically created ImageButton that I would like
I have some dynamically created rows/columns. What I'd like to do is set a
I have an <asp:CheckBoxList> using RepeatLayout=Flow in my page I dynamically assign values to.
I have a dynamically created Image control that is populated via a OpenFileDialog like:
I have a dynamically created textarea and like to replace it with jwysiwyg. I
I have a dynamically created select option using a javascript function. the select object
I have a CheckBoxList that displays a list of checkboxes using data from a
im having a problem with dynamic forms. I have dynamically created forms on button
I have to upload dynamically created data file to web server. One way to
I have a dynamically created list of labels and I am using GestureRecognizer for

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.