Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to hold a table of data for user edition (before saving in the the database)?
    primarykey
    data
    text
    <p>I've been using this programming style, that I've seen in an example and just started using it, because it does the job... I would like to know other programmers' opinion about it...</p> <p>So the situation is when you have a GridView, or a control based on it like the RadGrid, and you want to keep track of a data table while you are adding, editing, reordering and deleting rows.</p> <p>Using the session to hold the data table (or list of data) may not be the best solution, because the user may open two identical web pages… Using the ViewState to hold the data may be and option... I have been using an approach like the following:</p> <pre><code>public partial class DefaultPage : System.Web.UI.Page { protected DataLine DefaultDataLine() { DataLine dl = new DataLine(); dl = new DataLine(); dl.Number = 0; dl.Title = ""; dl.Text = ""; return dl; } protected class DataLine { public int Number { get; set; } public string Title { get; set; } public string Text { get; set; } } protected static List&lt;DataLine&gt; tempLines; protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { tempLines = RadGridBindStartUpData(); } } protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { RadGrid1.DataSource = tempLines; } protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; List&lt;DataLine&gt; table = tempLines; DataLine newRow = new DataLine (); RadTextBox rtb; rtb = (RadTextBox)editedItem.FindControl("RadTextBoxTitle"); newRow.Title = rtb.Text; rtb = (RadTextBox)editedItem.FindControl("RadTextBoxDescription"); newRow.Description = rtb.Text; RadNumericTextBox number = (RadNumericTextBox)editedItem.FindControl("RadNumericTextBoxNumber"); newRow.Number = number.Value.HasValue ? Convert.ToInt32(number.Value.Value) : 0; table.Add(newRow); } // ... </code></pre> <p>So using a static List variable, of a custom object (class), declared in the code-behind of the Aspx page, and updating it whenever the data is edited. </p> <p>What are your thoughts about this approach? Is it okay? How do you hold your table-format data for edition (prior to saving it in the database)? </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