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

  • SEARCH
  • Home
  • 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 3287678
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:31:13+00:00 2026-05-17T20:31:13+00:00

On !PostBack dynamic templates are created based on the number of rows needed for

  • 0

On !PostBack dynamic templates are created based on the number of rows needed for check boxes. The control id’s are chkbox_id. I am unable to retrieve the dynamic check boxes via the following code and NullReferenceException is always thrown.

The code before loops through the gridview rows, then datatable dt references the possible number of dynamic columns.

    for (int i = 0; i < dt.Rows.Count; i++)
    {
        string id = dt.Rows[i]["id"].ToString();

        CheckBox cb = (CheckBox)row.FindControl("ckbox_" + id);
        if (cb.Checked)
        { // do things  }

    }

Checkboxes defined here within page load:

if (!Page.IsPostBack)
{
    foreach (DataRow dRow in dt.Rows)
    {
        TemplateField ckhColumn = new TemplateField();
        ckhColumn.HeaderTemplate = new GridViewTemplate(ListItemType.Header, dRow["name"].ToString());
        ckhColumn.ItemTemplate = new GridViewTemplate(ListItemType.Item, "ckbox_" + dRow["id"].ToString());
        gvProductPriceList.Columns.Add(ckhColumn);
    }           
}

Let me know if I need to clarify anything else.

  • 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-17T20:31:13+00:00Added an answer on May 17, 2026 at 8:31 pm

    I’m not positive on this, and I don’t have a minute to try it, but it might work if you do a row.Parent.FindControl(...). Also, if you use the as operator instead of a direct cast, you won’t have the null reference exception (i.e. you can check for it):

    CheckBox cb = row.Parent.FindControl("ckbox_" + id) as CheckBox;
    if (cb != null)
    {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with dynamic controls. In Button1 postback I created several TextBox
In the website I'm currently building we need a large number of dynamic redirects,
I've a control that dynamically loads other user controls. Upon Async postback from one
I have a Page with a Dynamic User Control in a placeholder. When I
When I start a postback using __doPostBack, a file is created and going back
I've got a table which is partially made up of dynamic rows (comes from
I am generating 2 dropdown boxes and a CheckBoxList control at runtime using AJAX
I read about the dynamic control creation in ASP.NET this piece of text: ...When
The .NET ValidationSummary control aggregates error messages from validators that are fired on postback.
I want to create a dynamic DropDownList in ASP.NET, but after postback the DropDownList

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.