Note that there are some explanatory texts on larger screens.

plurals
  1. POBind data to nested grid in footer
    primarykey
    data
    text
    <p>I have added programatically button to the footer in RowDataBound:</p> <pre><code> else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[1].Text = "Total: "; e.Row.Cells[2].Text = totalStaff.ToString(); Button showStaff = new Button(); showStaff.CommandName = "ShowAll"; showStaff.Text = e.Row.Cells[2].Text.ToString(); e.Row.Cells[2].Controls.Add(showStaff); e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right; showStaff.Click += new EventHandler(showStaff_Click); } </code></pre> <p>now I want to handle showStaff_Click to bind data to nested gridview. I wrote bwlow code in RowCommand but index is null:</p> <pre><code> if(e.CommandName == "ShowAll") { int index = Convert.ToInt32(e.CommandArgument.ToString()); GridViewRow row = Staff.Rows[index]; GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo"); int TeamID = 0; int cityID = 3699; StaffInfo.DataSource = GetStaff(cityID, TeamID); StaffInfo.DataBind(); } </code></pre> <p>I will appreciate Your help.</p> <p>EDIT:</p> <p>I have nade some changes:</p> <pre><code> protected void Staff_RowCommand(object sender, GridViewCommandEventArgs e) { try { //Checking for command name which command/button is pressed if (e.CommandName == "ShowDetails") { GridView Staff = (GridView)sender; int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = Staff.Rows[index]; GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo"); int TeamID = Convert.ToInt16(Staff.DataKeys[index].Values[0].ToString()); int cityID = Convert.ToInt16(Staff.DataKeys[index].Values[1].ToString()); StaffInfo.DataSource = GetStaff(cityID, TeamID); StaffInfo.DataBind(); StaffInfo.Visible = true; } else if(e.CommandName == "ShowAll") { int index = Convert.ToInt32(e.CommandArgument); GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo"); int TeamID = 0; int cityID = 3699; StaffInfo.DataSource = GetStaff(cityID, TeamID); StaffInfo.DataBind(); StaffInfo.Visible = true; } } catch (Exception ex) { Response.Write(ex.Message); } } &lt;asp:GridView ID="Staff" runat="server" AutoGenerateColumns="false" OnRowCommand="Staff_RowCommand" DataKeyNames="TeamID,CityID" ShowFooter="True" HorizontalAlign="Center"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText=" Function"&gt; &lt;ItemTemplate&gt; &lt;asp:Label Width="150px" ID="Function" ItemStyle-HorizontalAlign="Center" runat="server" Text='&lt;%# Bind("Function") %&gt;'&gt;&lt;/asp:Label&gt; &lt;asp:GridView ID="StaffInfo" AutoGenerateColumns="false" runat="server"&gt; &lt;Columns&gt; &lt;asp:BoundField ItemStyle-Width="150px" DataField="FirstName" HeaderText="First Name" /&gt; &lt;asp:BoundField ItemStyle-Width="150px" DataField="LastName" HeaderText="Last Name" /&gt; &lt;asp:BoundField ItemStyle-Width="150px" DataField="SOEID" HeaderText="SOEID" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=" Team"&gt; &lt;ItemTemplate&gt; &lt;asp:Label Width="150px" ID="Team" ItemStyle-HorizontalAlign="Center" runat="server" Text='&lt;%# Bind("Team") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Staff Count"&gt; &lt;ItemTemplate&gt; &lt;asp:Button Width="40px" ID="StaffCount" ItemStyle-HorizontalAlign="Center" runat="server" Text='&lt;%# Bind("StaffCount") %&gt;' CommandName="ShowDetails" CommandArgument="&lt;%# ((GridViewRow)Container).RowIndex %&gt;" CausesValidation="True" UseSubmitBehavior="False" /&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;asp:Button id="TotalStaff" runat="server" Text="Button1" CommandName="ShowAll" CommandArgument="&lt;%# ((GridViewRow) Container).RowIndex %&gt;" CausesValidation="True" UseSubmitBehavior="False" /&gt; &lt;/FooterTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField Visible ="false"&gt; &lt;ItemTemplate&gt; &lt;asp:Label runat="server" Width="150px" DataField="TeamID" HeaderText="TeamID" &gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField Visible ="false"&gt; &lt;ItemTemplate&gt; &lt;asp:Label runat="server" ItemStyle-Width="150px" DataField="CityID" HeaderText="CityID"&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; </code></pre> <p></p> <p>When I try to click the ShowAll button ite returns that index is out of range. I made Response.Write(intex.ToString()) and it returns -1. The index number in case or row is returned correctly. The problem is with footer button. Could You please help me? </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.
    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