Solved

Datagrid nested within a datalist is not displaying any data

Posted on 2011-02-15
3
1,169 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 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