Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It may not be the brightest idea, but you can query the database for the current state, and the compare with what you have got from the web page during a postback button click, or something like that. Or you can go with Brians answer.</p> <p>It is possible to persist a list of objects into the Viewstate and access it in a consequent postback. The only thing is that the object you are trying to persist must be defined as serializable.</p> <p>Update: </p> <p>The ViewState approach</p> <p>I feel this may be suitable for your need, and it requires a bit of linq. You'd need to create a class as follows:</p> <pre><code>[Serializable()] public class OptionState { //the id of the item int ID {get;set;} //state of the checkbox bool Checked {get;set;} } </code></pre> <p>Note the Serializable attribute. This is required for the instance to persist to the viewstate.</p> <p>Add the list of options to the viewstate: </p> <pre><code>var lstOptions = (from x in &lt;your_option_store&gt; select new OptionState{ID = x.ID, Checked = x.Checked}).ToList(); ViewState.Add("options", lstOptions); </code></pre> <p>Here is a bit of code that should go into your button click:</p> <pre><code>foreach(GridViewRow row in gvOptions.Rows) { //not writing the bit of code //which gets the ID and the //state of checkbox of //the gridview row being processed OptionState currentState = GetOptionStateObjectFromRow(row); List&lt;OptionState&gt; lstStates = (List&lt;OptionState&gt;) ViewState["options"]; OptionState originalState = lstStates.FirstOrDefault(x =&gt; x.ID == currentState.ID); if(currentState.Checked != originalState.Checked) { //the appropriate db call needs to be done here. } } </code></pre>
    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.
    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