Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code ;
C#
<asp:GridView ID="grdIskalemleri" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="IskalemiId" GridLines="Vertical" OnRowDataBound="grdIskalemleri_RowDataBound">
                            <AlternatingRowStyle BackColor="#DCDCDC" />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
<asp:GridView ID="altGrid" runat="server">
                                    <Columns>
                                        <asp:BoundField DataField="Deneme" />

                                    </Columns>
                                </asp:GridView>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                
                             <asp:BoundField DataField="IskalemiAdi" />
                             <asp:BoundField  DataField="IskalemiId"/>
                            </Columns>
                            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                            <SortedAscendingCellStyle BackColor="#F1F1F1" />
                            <SortedAscendingHeaderStyle BackColor="#0000A9" />
                            <SortedDescendingCellStyle BackColor="#CAC9C9" />
                            <SortedDescendingHeaderStyle BackColor="#000065" />
                        </asp:GridView>

and
binding code;
C#
private void GrdIskalemiDoldur()
       {

           grdIskalemleri.DataSource = from A in db.eMakbuzIskalemis
                                       //join B in db.eIskalemis
                                       //on A.MIskalemiId equals B.IsKalemiId
                                       //group A by new
                                       //{
                                       //    B.IsKalemiAdi,
                                       //    B.IsKalemiId
                                       //} into E
                                       select new
                                       {
                                           IskalemiAdi = A.IsKalemiBaslikBirimFiyati,
                                           IskalemiId = A.IskalemiBaslikMiktar
                                           //IskalemiAdi = E.Key.IsKalemiAdi,
                                           //IskalemiId = E.Key.IsKalemiId,
                                       };
           grdIskalemleri.DataBind();
       }

Its not problem but I cant this;
C#
 protected void grdIskalemleri_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string Id = grdIskalemleri.DataKeys[e.Row.RowIndex].Value.ToString();
//my problem is Id is null.but I know It has value
            GridView yeni = e.Row.FindControl("altGrid") as GridView;
//I didnt use Id and my datasource is null.
            yeni.DataSource = from A in db.eMakbuzIskalemis
                              select new {
                                  Deneme=A.IskalemiBaslikMiktar
                              };
            yeni.DataBind();
        }

I need to use nested gridview.
Posted
Comments
So, what is the issue?

add condition in grdIskalemleri_RowDataBound event before find nested grid inside parent grid.

C#
protected void grdIskalemleri_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string Id = grdIskalemleri.DataKeys[e.Row.RowIndex].Value.ToString();
                //my problem is Id is null.but I know It has value
                GridView yeni = e.Row.FindControl("altGrid") as GridView;
                //I didnt use Id and my datasource is null.
                yeni.DataSource = from A in db.eMakbuzIskalemis
                                  select new
                                  {
                                      Deneme = A.IskalemiBaslikMiktar
                                  };
                yeni.DataBind();
            }
        }
 
Share this answer
 
Comments
[no name] 2-Dec-13 19:53pm    
do u give a sample?
ty for answer
do u give a sample?
ty for answer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900