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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:36:15+00:00 2026-05-15T13:36:15+00:00

As a workaround for the fact that asp:Checkboxes don’t have values, I am attempting

  • 0

As a workaround for the fact that asp:Checkboxes don’t have values, I am attempting to dynamically create the ID’s of checkboxes in a DataList so that it inserts the primary keys into the control ID. This is surprisingly difficult.

I have placed a PlaceHolder in my DataList ItemTemplate, then in the ItemCreated I create the checkboxes using string.Format("Checkbox{0}", DataBinder(e.Item.DataItem, "ID")). The problem is that this only works in a non-postback condition, as on postback the DataItem is null. And of course ItemDataBound isn’t called on PostBack so that won’t work either.

I can’t seem to find a good way to handle this short of if (IsPostback) dataList.Bind(), which i don’t think is a good way to do it.

Can anyone provide me with any alternatives here?

EDIT:

Some additional information. I just realized that part of the problem was because I actually have a DataList within a DataList. The reason DataItem is null is because there is no databinding on postback, and the child data is not saved to viewstate.

Basically, what i’m doing is This, although it’s using a DataList rather than Repeater. So, on postback, the Children collection doesn’t get set because ItemDataBound isn’t called on postback.

EDIT2: To clarify, the problem is largely because of the nested datalists. I have to set the datasource of the nested datalist to a collection field of the first datalist’s individual rows fields. On postback, there is no databinding, so it doesn’t work.

  • 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-15T13:36:16+00:00Added an answer on May 15, 2026 at 1:36 pm

    You could use a similar technique to the one I wrote up in this answer – add a regular CheckBox, and a HiddenField control in the ItemTemplate, and bind the HiddenField to the primary key value e.g.

    <ItemTemplate>
        <tr>
            <td>
                <asp:CheckBox runat="server" ID="MyCheckBox" AutoPostBack="true" oncheckedchanged="MyCheckBox_CheckedChanged"  />
                <asp:HiddenField runat="server" id="DatabaseKeyHiddenField" Value='<%# Eval("DatabaseKey") %>' />
            </td>
        </tr>
    </ItemTemplate>
    
    protected void MyCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox selectedCheckBox;
        DataListItem selectedDataListItem;
        HiddenField databaseKeyHiddenField;
        string databaseKey;
    
        // Cast the sender object to a CheckBox
        selectedCheckBox = (CheckBox)sender;
    
        // Walk up the tree one level so we get the container for both controls
        selectedDataListItem = (DataListItem)selectedCheckBox.Parent;
    
        // Get the HiddenField control ...
        databaseKeyHiddenField = (HiddenField)selectedDataListItem.FindControl("DatabaseKeyHiddenField");
    
        // ... and read the value
        databaseKey = databaseKeyHiddenField.Value;
    
        // Go off and do a database update based on the key we now have
        ...
    }
    

    It’s a bit of a workaround rather than exactly what you want to do, but it works!

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

Sidebar

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.