Solved

Datagrid nested within a datalist is not displaying any data

Posted on 2011-02-15
3
1,164 Views
Last Modified: 2012-05-11
I have a dataset that pulls back the following data:

QuizID      QuizName      BadgeName      BadgesEarned
1      Physical Fitness      Chocolate      0
1      Physical Fitness      Coffee      2
1      Physical Fitness      Fruit      1
1      Physical Fitness      Strawberry      1
1      Physical Fitness      Wheatgrass      0
2      Eating      Chocolate      1
2      Eating      Coffee      1
2      Eating      Fruit      3
2      Eating      Wheatgrass      1
3      Dieting      Chocolate      0
3      Dieting      Coffee      0
3      Dieting      Fruit      0
3      Dieting      Strawberry      0
3      Dieting      Wheatgrass      0

On my aspx page I have the following code:

<asp:DataList id="gvAdminBadingHistory" DataKeyField="QuizID" OnItemDataBound="gvAdminBadgingHistory_ItemDataBound" gridlines="both" runat="server">

<HeaderTemplate>

</HeaderTemplate>

<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "QuizName") %>

<asp:DataGrid runat="server" ID="gvBadges" DataKeyField="QuizID" AutoGenerateColumns="false">
<Columns>
                           
                           <asp:TemplateColumn>
                            <FooterStyle />
                            <HeaderStyle />
                            <ItemStyle />
                        <EditItemTemplate>
                            <!-- child controls -->
                        </EditItemTemplate>
                        <FooterTemplate>
                            <!-- child controls -->
                        </FooterTemplate>
                        <HeaderTemplate>
                            <!-- child controls -->
                        </HeaderTemplate>
                        <ItemTemplate>
                            <ItemTemplate>
                                    <asp:Label ID="lblBadgeName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "BadgeName") %>'></asp:Label>
                                </ItemTemplate>

                        </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn>
                            <FooterStyle />
                            <HeaderStyle />
                            <ItemStyle />
                        <EditItemTemplate>
                            <!-- child controls -->
                        </EditItemTemplate>
                        <FooterTemplate>
                            <!-- child controls -->
                        </FooterTemplate>
                        <HeaderTemplate>
                            <!-- child controls -->
                        </HeaderTemplate>
                        <ItemTemplate>
                            <ItemTemplate>
                                    <asp:Label ID="lblBadgesEarned" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "BadgesEarned") %>'></asp:Label>
                                </ItemTemplate>

                        </ItemTemplate>
                </asp:TemplateColumn>


               
                        </Columns>


</asp:DataGrid>
</ItemTemplate>

<FooterTemplate>

</FooterTemplate>

</asp:DataList>

On my .cs page I have the following code:

        protected void gvAdminBadgingHistory_ItemDataBound(object sender, DataListItemEventArgs e)
        {
           



        }

What code do I need to put inside of the ItemDataBound event so that my datagrid will populate with the BadgeNames and BadgesEarned columns from my dataset for each QuizID?
0
Comment
Question by:jjliu4492
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 34903333
Have you binded the datasource for the data list to the dataset you have given here?

Do you get values for Quizname in the datalist, but no values in DataGrid?
0
 

Author Comment

by:jjliu4492
ID: 34910100
Yes I have binded the datasource for the datalist to the dataset.

The datalist populates with the QuizName from the dataset, but the nested datagrid does not populate with the BadgeName and BadgesEarned frmo the dataset.
0
 
LVL 13

Accepted Solution

by:
hiteshgoldeneye earned 500 total points
ID: 34913302
In your ItemDataBound method you need to call the BindGrid method for the item that is selected, we can grab the data key value from the DataKey collection for the main grid item (e.Item). In your BindGrid method:

    gvBadges.DataSource = getBadge(gvAdminBadingHistory.DataKeys(e.Item.ItemIndex))


please refer the link below for more details
http://p2p.wrox.com/asp-net-1-1/30602-datagrid-nested-datalist-passing-parameters.html
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create a Dropdown list with sub group 10 43
CSS question 16 63
C# LINQ query question 11 33
Binding a GridView in ASP.NET(VB) using Using statements 6 19
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question