Solved

Datagrid nested within a datalist is not displaying any data

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
detecting  the added row index in a datagridview 3 54
DataGridView Events ? 3 37
Syntax Error 2 41
Error in JQuery 5 34
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

1 Experts available now in Live!

Get 1:1 Help Now