Note that there are some explanatory texts on larger screens.

plurals
  1. POGridView not returning databound rows when OnClick event fires
    primarykey
    data
    text
    <p>I have a GridView that is made up of two database fields populated via a stored procedure and then three fields for user input (two checkbox controls and one textbox) when I click on the save button I can get the information from the three controls but nothing from the two that were populated via the database. How can I get the first two fields?</p> <pre><code>&lt;asp:GridView ID="gvA1" runat="server" AutoGenerateColumns="false" DataKeyNames="CodeNo" AutoGenerateSelectButton="false" EnablePersistedSelection="True" Visible="false"&gt; &lt;Columns&gt; &lt;asp:TemplateField Visible="false" &gt; &lt;ItemTemplate&gt; &lt;%#DataBinder.Eval(Container.DataItem, "CodeNo")%&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField ItemStyle-Wrap="true" ItemStyle-Width="400px" HeaderText="Violation"&gt; &lt;ItemTemplate&gt; &lt;%#DataBinder.Eval(Container.DataItem, "CodeViolationCited") %&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="A1Accordion_cbPool" runat="server" Text="Pool:" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="A1Accordion_cbSpa" runat="server" Text="Spa:" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Additional Comments" Visible="true"&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="A1Accordion_tb" runat="server" TextMode="MultiLine"&gt;&lt;/asp:TextBox&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>Code Behind:</p> <pre><code>protected void SaveAndCollapseA1(object sender, EventArgs e) { //good stuff CheckBox myCheckBox_1 = gvA1.Rows[0].FindControl("A1Accordion_cbPool") as CheckBox; CheckBox myCheckBox_2 = gvA1.Rows[0].FindControl("A1Accordion_cbSpa") as CheckBox; TextBox myTextBox = gvA1.Rows[0].FindControl("A1Accordion_tb") as TextBox; //not so good stuff String myString1 = gvA1.Rows[0].Cells[0].ToString(); String myString2 = gvA1.Rows[0].Cells[1].ToString(); } </code></pre> <p>I figured it out but I haven't been hear long enough to post the solution via the links but if you change the columns as so:</p> <pre><code>&lt;asp:label ID="lblA1CodeNo" runat="server" text='&lt;%# Eval("CodeNo") %&gt;'&gt;&lt;/asp:label&gt; </code></pre> <p>then the values are available...</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