Table Fields : Genre, Album., Title
Dont need writing VB/C# code for this sample
I like design mode, dont like writing code too much. So, this is my sample code creating NESTED Gridviews without VB/C# code. To use this code simply create table like above and create connection string in web.config called "TESTConnectionString" and copy-paste code below to your aspx page.
ASPX
<form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Horizontal" ShowHeader="False" Width="100%"> <Columns> <asp:TemplateField HeaderText="Genre" SortExpression="Genre"> <ItemTemplate> Genre : <asp:Label ID="Label1" runat="server" style="color: #FF0000; font-weight: 700;" Text='<%# Bind("Genre") %>'></asp:Label> <br /> <table class="style1"> <tr> <td class="style2"> </td> <td> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" GridLines="None" ShowHeader="False" Width="100%"> <Columns> <asp:TemplateField HeaderText="Album" SortExpression="Album"> <ItemTemplate> Album : <asp:Label ID="Label1" runat="server" style="color: #0000FF; font-weight: 700" Text='<%# Bind("Album") %>'></asp:Label> <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("Genre") %>' /> <table class="style1"> <tr> <td class="style2"> </td> <td> <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" ShowHeader="False" Width="100%"> <RowStyle BackColor="#F7F7DE" /> <Columns> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> </Columns> <FooterStyle BackColor="#CCCC99" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> </td> </tr> </table> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" SelectCommand="SELECT [Title] FROM [Music] WHERE (([Album] = @Album) AND ([Genre] = @Genre)) ORDER BY [Title]"> <SelectParameters> <asp:ControlParameter ControlID="Label1" Name="Album" PropertyName="Text" Type="String" /> <asp:ControlParameter ControlID="HiddenField1" Name="Genre" PropertyName="Value" Type="String" /> </SelectParameters> </asp:SqlDataSource> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Album") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </td> </tr> </table> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" SelectCommand="SELECT DISTINCT [Album], [Genre] FROM [Music] WHERE (([Genre] = @Genre) AND ([Album] IS NOT NULL))"> <SelectParameters> <asp:ControlParameter ControlID="Label1" Name="Genre" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Genre") %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCC99" ForeColor="Black" /> <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" /> <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" SelectCommand="SELECT DISTINCT [Genre] FROM [Music] WHERE ([Genre] IS NOT NULL)"> </asp:SqlDataSource> </form>
No comments:
Post a Comment