Note that there are some explanatory texts on larger screens.

plurals
  1. POGridView, Accessing child GridView checkbox
    text
    copied!<p>I have a parent GridView that had a child GridView (code below), how do I get the value of the child gridview checkbox? And also, how do I save the state of the child gridview, i.e. if it is displayed or not? This is the function that is fired when the button is pressed that reads through the parent grid seeing which publications have been selected:</p> <pre><code>protected void DeleteSelectedProducts_Click(object sender, EventArgs e) { bool atLeastOneRowDeleted = false; // Iterate through the Products.Rows property foreach (GridViewRow row in GridView1.Rows) { // Access the CheckBox CheckBox cb = (CheckBox)row.FindControl("PublicationSelector"); if (cb != null &amp;&amp; cb.Checked) { // Delete row! (Well, not really...) atLeastOneRowDeleted = true; // First, get the ProductID for the selected row int productID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value); // "Delete" the row DeleteResults.Text += string.Format( "This would have deleted ProductID {0}&lt;br /&gt;", productID); //DeleteResults.Text = "something"; } // Show the Label if at least one row was deleted... DeleteResults.Visible = atLeastOneRowDeleted; } } &lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PublicationID" DataSourceID="ObjectDataSource1" Width="467px" OnRowDataBound="GridView1_RowDataBound" Font-Names="Verdana" Font-Size="Small"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="PublicationSelector" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" /&gt; &lt;asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /&gt; &lt;asp:BoundField DataField="State" HeaderText="State" SortExpression="State" /&gt; &lt;asp:TemplateField HeaderText="Owners"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="Owners" runat="server"&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;ItemStyle HorizontalAlign="Center" /&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" /&gt; &lt;asp:TemplateField HeaderStyle-CssClass="hidden-column" ItemStyle-CssClass="hidden-column" FooterStyle-CssClass="hidden-column"&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td colspan="8" &gt; &lt;div id="&lt;%# Eval("PublicationID") %&gt;" style="display: none; position: relative;" &gt; &lt;asp:GridView ID="GridView2_ABPubs" runat="server" AutoGenerateColumns="false" Width="100%" DataKeyNames="PublicationID" Font-Names="Verdana" Font-Size="small"&gt; &lt;Columns&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="ChildPublicationSelector" runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="shoom_dev._Default"&gt; &lt;/asp:ObjectDataSource&gt; &lt;p&gt; &lt;asp:Button ID="DeleteSelectedProducts" runat="server" Text="Delete Selected Products" onclick="DeleteSelectedProducts_Click" /&gt; &lt;/p&gt; &lt;p&gt; &lt;asp:Label ID="DeleteResults" runat="server" EnableViewState="False" Visible="False"&gt;&lt;/asp:Label&gt; &lt;/p&gt; </code></pre>
 

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