Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. protected void Staff_RowCommand(object sender, GridViewCommandEventArgs e)
  2. {
  3. try
  4. {
  5. //Checking for command name which command/button is pressed
  6. if (e.CommandName == "ShowDetails")
  7. {
  8. GridView Staff = (GridView)sender;
  9.  
  10. int index = Convert.ToInt32(e.CommandArgument);
  11. GridViewRow row = Staff.Rows[index];
  12. GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo");
  13. int TeamID = Convert.ToInt16(Staff.DataKeys[index].Values[0].ToString());
  14. int cityID = Convert.ToInt16(Staff.DataKeys[index].Values[1].ToString());
  15. StaffInfo.DataSource = GetStaff(cityID, TeamID);
  16. StaffInfo.DataBind();
  17. StaffInfo.Visible = true;
  18. }
  19. else if(e.CommandName == "ShowAll")
  20. {
  21. int index = Convert.ToInt32(e.CommandArgument);
  22. GridView StaffInfo = (GridView)Staff.Rows[index].FindControl("StaffInfo");
  23. int TeamID = 0;
  24. int cityID = 3699;
  25. StaffInfo.DataSource = GetStaff(cityID, TeamID);
  26. StaffInfo.DataBind();
  27. StaffInfo.Visible = true;
  28. }
  29. }
  30. catch (Exception ex)
  31. {
  32. Response.Write(ex.Message);
  33. }
  34. }
  35.  
  36. <asp:GridView ID="Staff" runat="server" AutoGenerateColumns="false"
  37. OnRowCommand="Staff_RowCommand"
  38. DataKeyNames="TeamID,CityID" ShowFooter="True" HorizontalAlign="Center">
  39. <Columns>
  40. <asp:TemplateField HeaderText=" Function">
  41. <ItemTemplate>
  42. <asp:Label Width="150px" ID="Function" ItemStyle-HorizontalAlign="Center" runat="server" Text='<%# Bind("Function") %>'></asp:Label>
  43. <asp:GridView ID="StaffInfo" AutoGenerateColumns="false" runat="server">
  44. <Columns>
  45. <asp:BoundField ItemStyle-Width="150px" DataField="FirstName" HeaderText="First Name" />
  46. <asp:BoundField ItemStyle-Width="150px" DataField="LastName" HeaderText="Last Name" />
  47. <asp:BoundField ItemStyle-Width="150px" DataField="SOEID" HeaderText="SOEID" />
  48. </Columns>
  49. </asp:GridView>
  50. </ItemTemplate>
  51. </asp:TemplateField>
  52. <asp:TemplateField HeaderText=" Team">
  53. <ItemTemplate>
  54. <asp:Label Width="150px" ID="Team" ItemStyle-HorizontalAlign="Center" runat="server" Text='<%# Bind("Team") %>'></asp:Label>
  55. </ItemTemplate>
  56. </asp:TemplateField>
  57. <asp:TemplateField HeaderText="Staff Count">
  58. <ItemTemplate>
  59. <asp:Button Width="40px" ID="StaffCount" ItemStyle-HorizontalAlign="Center" runat="server" Text='<%# Bind("StaffCount") %>' CommandName="ShowDetails" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" CausesValidation="True" UseSubmitBehavior="False" />
  60. </ItemTemplate>
  61. <FooterTemplate>
  62. <asp:Button id="TotalStaff" runat="server" Text="Button1" CommandName="ShowAll" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CausesValidation="True" UseSubmitBehavior="False" />
  63. </FooterTemplate>
  64. </asp:TemplateField>
  65. <asp:TemplateField Visible ="false">
  66. <ItemTemplate>
  67. <asp:Label runat="server" Width="150px" DataField="TeamID" HeaderText="TeamID" ></asp:Label>
  68. </ItemTemplate>
  69. </asp:TemplateField>
  70. <asp:TemplateField Visible ="false">
  71. <ItemTemplate>
  72. <asp:Label runat="server" ItemStyle-Width="150px" DataField="CityID" HeaderText="CityID"></asp:Label>
  73. </ItemTemplate>
  74. </asp:TemplateField>
  75. </Columns>
  76.  
  77. gridview1.FooterRow // Use name of your gridview
  78.  
  79. var rowIndexForFooter = gridview.Rows.Count - 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement