Untitled


SUBMITTED BY: Guest

DATE: April 18, 2014, 7:29 p.m.

FORMAT: HTML

SIZE: 4.5 kB

HITS: 859

  1. //No declaring datasource this time, that's in the code behind because I need to update shit, you'll see it there
  2. <asp:GridView
  3. id="UsersGridView"
  4. runat="server"
  5. AutoGenerateEditButton="True" // makes a column with an edit button, it doesn't automatically do everything
  6. AutoGenerateColumns = "false" //gotta put in all the columns I need, not just the remove one like last time. This is for the update
  7. //these three you'll see
  8. OnRowCancelingEdit="UsersGridView_RowCancelingEdit"
  9. OnRowUpdating="UsersGridView_RowUpdating"
  10. OnRowEditing="UsersGridView_RowEditing"
  11. //style
  12. BackColor="White" BorderColor="#3366CC" BorderStyle="None"
  13. BorderWidth="1px" CellPadding="4">
  14. <Columns>
  15. //declaring columns. Skip the remove one (the first) and take a look at what is needed for the editing and updating to work
  16. <asp:TemplateField HeaderText="Remove users" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ShowHeader="false" HeaderStyle-Height="40px">
  17. <ItemTemplate>
  18. <asp:LinkButton ID="Remove" Text="Remove" OnClick="RemoveUser" CommandArgument='<%# Eval("userName") %>' CommandName="RemoveUser" runat="server"></asp:LinkButton>
  19. </ItemTemplate>
  20. <HeaderStyle Height="40px" CssClass="leftborder"></HeaderStyle>
  21. <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="33px"></ItemStyle>
  22. </asp:TemplateField>
  23. //here we go, not remove.
  24. <asp:TemplateField HeaderText="User Name">
  25. <ItemTemplate>
  26. <asp:Label ID="UserNamelbl" runat="server" Text='<%# Eval("userName") %>'></asp:Label>//a label to show something
  27. </ItemTemplate>
  28. <EditItemTemplate>
  29. <asp:TextBox ID="UserNameEdit" Width="100" Text='<%# Eval("userName") %>' Enabled="true" runat="server"></asp:TextBox>// a textbox to edit. the rest is the same (give or take)
  30. </EditItemTemplate>
  31. </asp:TemplateField>
  32. <asp:TemplateField HeaderText="Email">
  33. <ItemTemplate>
  34. <asp:Label ID="Emaillbl" runat="server" Text='<%# Eval("email") %>'></asp:Label>
  35. </ItemTemplate>
  36. <EditItemTemplate>
  37. <asp:TextBox ID="EmailEdit" Width="150" Text='<%# Eval("email") %>' Enabled="true" runat="server"></asp:TextBox>
  38. </EditItemTemplate>
  39. </asp:TemplateField>
  40. //checkbox here! Slightly different but around the same.
  41. <asp:TemplateField HeaderText="Admin">
  42. <ItemTemplate>
  43. <asp:CheckBox ID="IsAdminBox" runat="server" Enabled="false" Checked='<%# bool.Parse(Eval("isAdmin").ToString()) %>' />
  44. </ItemTemplate>
  45. <EditItemTemplate>
  46. <asp:CheckBox ID="IsAdminBoxEdit" runat="server" Checked='<%# bool.Parse(Eval("isAdmin").ToString()) %>' Enabled="true" />
  47. </EditItemTemplate>
  48. </asp:TemplateField>
  49. </Columns>
  50. //style
  51. <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
  52. <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
  53. <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
  54. <RowStyle BackColor="White" ForeColor="#003399" />
  55. <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
  56. <SortedAscendingCellStyle BackColor="#EDF6F6" />
  57. <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
  58. <SortedDescendingCellStyle BackColor="#D6DFDF" />
  59. <SortedDescendingHeaderStyle BackColor="#002876" />
  60. </asp:GridView>

comments powered by Disqus