Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating dynamic DataList controls with ID's based on bound data
    primarykey
    data
    text
    <p>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.</p> <p>I have placed a PlaceHolder in my DataList ItemTemplate, then in the ItemCreated I create the checkboxes using <code>string.Format("Checkbox{0}", DataBinder(e.Item.DataItem, "ID"))</code>. 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. </p> <p>I can't seem to find a good way to handle this short of <code>if (IsPostback) dataList.Bind()</code>, which i don't think is a good way to do it.</p> <p>Can anyone provide me with any alternatives here?</p> <p>EDIT:</p> <p>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. </p> <p>Basically, what i'm doing is <a href="https://stackoverflow.com/questions/3078801/how-to-create-category-and-list-in-one-query-with-linq">This</a>, 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.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload