From: Guabble on 5 Feb 2007 06:06 Hi Can anyone help me? I want to be able to show my sqldatareader contents in a gridview whereby the child data is concatenated up in a single row. Is this possible? For example Author Name Book Titles Author1 Book1, Book2, Book3 Author2 Book 4, Book7 I can get it so that it binds, but displays a separate row of each Book name. Which is rubbish. I believe, as a alternative to my desired result, I can create like a little nested gridview instead of the Boot Titles column, which when click displays a list of titles. Is this possible? Or did I just dream it? Any ideas how to show this child data? Thanks for any help regarding this? cheers, Mike
From: Adrian Jones on 5 Feb 2007 07:13 Try using a repeater control for your child data.
From: Guabble on 5 Feb 2007 07:52 On Feb 5, 12:13 pm, Adrian Jones <AdrianJo...(a)discussions.microsoft.com> wrote: > Try using a repeater control for your child data. How would that work, would I have to loop through the recordset rows, grabbing the book title, concatenating them and outputting them. Sorry i've never used a repeater before, from what I've read about them, I thought they were mainly used to provide custom formatting to grid cells. Do you have any examples by any chance cheers Mike
From: Adrian Jones on 5 Feb 2007 08:25 Hi Mike, I'm a relative newbie to ASP.NET, so please excuse me if anything here is done a bit back to front. But I've just used something like this to solve something similiar to what you describe: <!-- ========================================== Gridview with repeater ========================================== --> <asp:GridView ID="gvParent" runat="server" AutoGenerateColumns="False" DataSourceID="sqlParent" DataKeyNames="ParentID" OnRowDataBound="gvParent_RowDataBound" > <Columns> <asp:TemplateField HeaderText="Description"> <ItemTemplate> <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Child Data "> <ItemTemplate> <asp:Repeater ID="rptChild" runat="server"> <ItemTemplate> <asp:Label ID="lblChildDataField" runat="server" Text='<%# Eval("ChildDataField") %>'/> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <!-- ================================================= SQL sources for Parent and Child ================================================ --> <asp:SqlDataSource ID="sqlChild" runat="server" ConnectionString="<%$ ConnectionStrings:connString %>" SelectCommand="GetChildData" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:ControlParameter ControlID="gvParent" Name="ParentID" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="sqlParent" runat="server" ConnectionString="<%$ ConnectionStrings:connString %>" SelectCommand="GetParentData" SelectCommandType="StoredProcedure"> </asp:SqlDataSource> <-- In code-behind to databind each set of child data when parent is databound ================================================= --> protected void gvParent_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Repeater rep = (Repeater)e.Row.FindControl("rptChild"); string ID = gvParent.DataKeys[e.Row.DataItemIndex].Value.ToString(); sqlChild.SelectParameters[0].DefaultValue = ID; DataView dv = (DataView)sqlChild.Select (DataSourceSelectArguments.Empty); rep.DataSource = dv; rep.DataBind(); } }
From: Guabble on 5 Feb 2007 09:39
cheers dude, will try it out.... thanks heaps Mike |