Pinakin
Pinakin

Reputation: 21

How to get cell value to update data from nested gridview?

I have 2 gridview. Gridview Inside gridview. first gridview shows sum of same invoice number and party name etc..., when i click Plus symbol it shows Multiple Entries inside 2nd gridview. I want to edit those entry. for that I just need my primary key value Id. so i can fetch data and can update. How to get ID from 2nd Gridview? Please Help me. Thank you in advanced.

This is Image I have took to know What exactly I want. Please Click This

enter image description here

This is HTML Code using ASP.NET

<div style="overflow:auto; width:100%; margin-left:0px; ">
        <asp:GridView ID="grdUpdateSells" runat="server" AutoGenerateColumns="False" CellPadding="7" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True" ShowFooter="True" DataSourceID="SqlDataSource1" DataKeyNames="Invone" OnRowDataBound="grdUpdateSells_RowDataBound" >
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <img alt = "" style="cursor: pointer" src="../images/plus.png" width="24" height="24" />
                            <asp:Panel ID="pnlChild" runat="server" Style="display: none">
                                <asp:GridView ID="grdUpdateData" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True" ShowFooter="False" OnRowCommand="grdUpdateData_SellsEdit">
                                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                    <Columns>
                                        <asp:TemplateField HeaderText="ID" Visible="false">
                                            <ItemTemplate>
                                                <asp:Label ID="lblId" Text='<%# Eval("Id") %>' runat="server"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>

                                        <asp:ButtonField CommandName="SellsEdit" Text="Edit" />

                                        <asp:BoundField DataField="Invone" HeaderText="Invoice No" SortExpression="Invone">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="InvDate" HeaderText="Invoice Date" DataFormatString="{0:dd/MMM/yyyy}">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Terms" HeaderText="Terms">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="DueDate" HeaderText="Due Date" DataFormatString="{0:dd/MMM/yyyy}">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Pieces" HeaderText="Pieces">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Carats" HeaderText="Carats" FooterText="Total">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Price" HeaderText="Price">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="GrossAmt" HeaderText="Gross Amount">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Discount1" HeaderText="Discount 1">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="DisAmt1" HeaderText="Discounted Amount 1">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Discount2" HeaderText="Discount2">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="DisAmt2" HeaderText="Discounted Amount 1">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="FinalAmt" HeaderText="Final Amount">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Party" HeaderText="Party">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Person" HeaderText="Person">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Shape" HeaderText="Shape">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="Quality" HeaderText="Quality">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>

                                        <asp:BoundField DataField="SalesExe" HeaderText="Sales Executive">
                                        <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                                        <ItemStyle HorizontalAlign="Center" Wrap="False" />
                                        </asp:BoundField>
                                    </Columns>
                                    <EditRowStyle BackColor="#999999" />
                                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                    <SortedAscendingCellStyle BackColor="#E9E7E2" />
                                    <SortedAscendingHeaderStyle BackColor="#506C8C" />
                                    <SortedDescendingCellStyle BackColor="#FFFDF8" />
                                    <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                                </asp:GridView>
                            </asp:Panel>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="Invoice No" DataField="Invone"/>
                    <asp:BoundField HeaderText="Invoice Date" DataField="InvDate"/>
                    <asp:BoundField HeaderText="Type" DataField="Type"/>
                    <asp:BoundField HeaderText="Terms" DataField="Terms"/>
                    <asp:BoundField HeaderText="Due Date" DataField="DueDate"/>
                    <asp:BoundField HeaderText="Pieces" DataField="SumPieces"/>
                    <asp:BoundField HeaderText="Carats" DataField="SumCarats"/>
                    <asp:BoundField HeaderText="Gross Amount" DataField="SumGrossAmt"/>
                    <asp:BoundField HeaderText="Discount Amount 1" DataField="SumDisAmt1"/>
                    <asp:BoundField HeaderText="Discount Amount 2" DataField="SumDisAmt2"/>
                    <asp:BoundField HeaderText="Final Amount" DataField="SumFinalAmt"/>
                    <asp:BoundField HeaderText="Party" DataField="Party"/>
                    <asp:BoundField HeaderText="Person" DataField="Person"/>
                    <asp:BoundField HeaderText="Sales Executive" DataField="SalesExe"/>
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>
        <asp:Label ID="lblGridSelectID" runat="server" Text="Label" Visible="false"></asp:Label>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=PINAKIN-IT;Initial Catalog=kiranexportshk;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [Invone], [InvDate], [Type], [Terms], [DueDate], sum([Pieces]) AS [SumPieces], sum([Carats]) AS [SumCarats], sum([GrossAmt]) AS [SumGrossAmt], sum([DisAmt1]) AS [SumDisAmt1], sum([DisAmt2]) AS [SumDisAmt2], sum([FinalAmt]) AS [SumFinalAmt], [Party], [Person], [SalesExe] FROM [Sells] Group By [Invone], [InvDate], [Type], [Terms], [DueDate], [Party], [Person], [SalesExe]  ORDER BY [Invone] DESC"></asp:SqlDataSource>

        </div>

Upvotes: 1

Views: 1481

Answers (1)

I wrote one solution for this.

C# code:

protected void grdUpdateData_SellsEdit(object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName == "Edit")
    {   
        GridView grdUpdateData = (sender as GridView);
        int index = Convert.ToInt32(e.CommandArgument);   
        GridViewRow row = grdUpdateData.Rows[index];     
        int RowId = Convert.ToInt32((row.Cells[0].FindControl("lblId") as Label).Text);
    }
}

Make some changes in HTML code:

<asp:TemplateField HeaderText="ID" ItemStyle-CssClass="Hide" HeaderStyle-CssClass="Hide"> //Include CSS to hide the column instead of using Visible = "false"
    <ItemTemplate>
        <asp:Label ID="lblId" Text='<%# Eval("Id") %>' runat="server"></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

CSS code:

 <style type="text/css">
    .Hide
    {
        display: none;
    }
 </style>

Hope this help!

Upvotes: 1

Related Questions