|
How To Embed DataList Inside ASP.Net DataGrid Control
In our earlier article,
Embed ASP.Net DataGrid Control Inside Another DataGrid Control we
demonstrated how can you embed a grid inside a grid. In this article we show
the same technique. The only difference is that we show how a DataList
control can be embeded inside DataGrid control.
The demo project for this article binds the master data grid with authors
data table of pubs database. From that table we show au_fname and au_lname
fields. We also get au_id field for each record but that value is not
shown. The au_id value is used to query title and titleauthor
table to query titles published by each author. And then those titles are
displaued in DataList inside the master data grid.
<asp:datagrid id="Authors_DataGrid" Runat="server" BorderColor="White" BorderStyle="Ridge" CellSpacing="1"
BorderWidth="2px" BackColor="White" CellPadding="3" GridLines="Horizontal" AutoGenerateColumns="False"
AllowSorting="True" AllowPaging="True" DataMember="authors" PageSize=7>
<ItemStyle ForeColor="Black" BackColor="#DEDFDE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#E7E7FF" BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="au_lname" SortExpression="au_lname" HeaderText="Last Name"></asp:BoundColumn>
<asp:BoundColumn DataField="au_fname" SortExpression="au_fname" HeaderText="First Name"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Titles">
<ItemTemplate>
<asp:datalist id="Titles_DataList" Runat="server" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="4" ShowHeader="False" >
<AlternatingItemStyle ForeColor="Navy" />
<ItemStyle ForeColor="Blue" BackColor="#DEDFDE" />
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "title") %>
</ItemTemplate>
</asp:datalist>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="#C6C3C6" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
We will not explain all the code here because it is pretty much the same as
previous article. Please feel free to download the project and
experience it yourself.
|