Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting an object back from my GridView rows
    primarykey
    data
    text
    <p>Basically, i want my object back...</p> <p>I have an Email object.</p> <pre><code>public class Email{ public string emailAddress; public bool primary; public int contactPoint; public int databasePrimaryKey; public Email(){} } </code></pre> <p>In my usercontrol, i a list of Email objects.</p> <pre><code>public List&lt;Email&gt; EmailCollection; </code></pre> <p>And i'm binding this to a GridView inside my usercontrol.</p> <pre><code>if(this.EmailCollection.Count &gt; 0){ this.GridView1.DataSource = EmailCollection; this.GridView1.DataBind(); } </code></pre> <p>It would be really awesome, if i could get an Email object back <em>out</em> of the GridView later.</p> <p>How do i do this?</p> <p>I'm also binding only some of the Email object's properties to the GridView as well and they're put into Item Templates.</p> <pre><code>&lt;Columns&gt; &lt;asp:TemplateField HeaderText="Email Address"&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Text=&lt;%# Eval("EmailAddress") %&gt; Width=250px /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Primary"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox runat="server" Checked=&lt;%# Eval("PrimaryEmail") %&gt; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Contact Point"&gt; &lt;ItemTemplate&gt; &lt;CRM:QualDropDown runat="server" Type=ContactPoint InitialValue=&lt;%# Eval("ContactPoint") %&gt; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; </code></pre> <p>Can GridView even do this? Do i need to roll my own thing? It'd be really cool if it would do it for me.</p> <hr> <p>To elaborate more. </p> <p>I am saving the List collection into the viewstate. </p> <p>What I'm eventually trying to get to, is there will be a Save button somewhere in the control, which when the event fires I'd like to create an Email object from a datarow in the GridView which to compare to my original List collection. Then if there's a change, then I'd update that row in the database. I was thinking that if I could put a List collection into a GridView, then perhaps I could get it right back out.</p> <p>Perhaps I create a new constructor for my Email object which takes a DataRow? But then there's a lot of complexities that goes into that...</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.
 

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