Solved

Datagrid nested within a datalist is not displaying any data

Posted on 2011-02-15
3
1,122 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
  • 2
3 Comments
 
LVL 13

Expert Comment

by:hiteshgoldeneye
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now