Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using asp.net3.5 with C#. I have nested gridview, i want that when i click the button in the inner most gridview
i get the actual row in which the gridview is selected, so as to perform the other task. I can very well get the row of the button clicked, but the problem is in which row the current gridview is located of the upper gridview. my nested grid is like this
XML
<asp:GridView ID="gvRoomsType" runat="server" AutoGenerateColumns="False" Width="100%" CellPadding="4" ForeColor="White" GridLines="Horizontal">
    <RowStyle BackColor="#1C5E55" />
    <Columns>
        <asp:TemplateField ItemStyle-HorizontalAlign="Left">
            <HeaderTemplate>ROOM WITH STUDENT DETAILS</HeaderTemplate>
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text="Room Type  :" Width="12%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="lblRoomtype" runat="server" Text="<% #Bind('RoomType') %>" Width="5%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="Label4" runat="server" Text="Beds/Room  :" Width="12%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="lblBeds" runat="server" Text="<% #Bind('Beds') %>" Width="5%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="Label6" runat="server" Text="Total Rooms :" Width="13%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="Label7" runat="server" Text="<% #Bind('totalrooms') %>" Width="5%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="Label12" runat="server" Text="Occupied Beds :" Width="14%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="Label13" runat="server" Text="<% #Bind('Occupied') %>" Width="5%" BackColor="#1C5E55" ForeColor="Red"></asp:Label>
                <asp:Label ID="Label10" runat="server" Text="Vecant Beds :" Width="14%" BackColor="#1C5E55"></asp:Label>
                <asp:Label ID="Label11" runat="server" Text="<% #Bind('VecantBeds') %>" Width="5%" BackColor="#1C5E55" ForeColor="Green"></asp:Label><br />
                <asp:GridView ID="gvRoomNo" runat="server" AutoGenerateColumns="false" Width="100%" ShowHeader="false">
                    <RowStyle BackColor="#CC6600" />
                    <Columns>
                        <asp:TemplateField ItemStyle-HorizontalAlign="Left">
                            <ItemTemplate>
                                <asp:Label ID="Label5" runat="server" Text="Room No.:" Width="10%"></asp:Label>
                                <asp:Label ID="lblRoomid" runat="server" Text="<% #Bind('RoomId') %>" Width="15%"></asp:Label>
                                <asp:Label ID="Label9" runat="server" Text=" Floor  :" Width="10%"></asp:Label>
                                <asp:Label ID="Label8" runat="server" Text="<% #Bind('Floor') %>" Width="5%"></asp:Label>
                                <asp:Label ID="Label10" runat="server" Text="Vecant Beds :" Width="14%"></asp:Label>
                                <asp:Label ID="Label11" runat="server" Text="<% #Bind('vecant') %>" Width="5%" ForeColor="Green"></asp:Label><br />
                                <asp:GridView ID="gvStudent" runat="server" AutoGenerateColumns="false"
                                    Width="100%" ShowHeader="false">
                                    <RowStyle BackColor="#FF9900" />
                                    <Columns>
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <div style="float:left; width:30%">
                                                    <asp:Image ID="imgPic" ImageAlign="AbsMiddle" Height="50px" runat="server"
                                                        ImageUrl="<% #Bind('Pic') %>" />
                                                </div>
                                                <div style="float:Right; width:69%; text-align:left">
                                                    <asp:Label ID="Label1" runat="server" Text="Name    :"></asp:Label>
                                                    <asp:Label ID="lblName" runat="server" Text="<% #Bind('StudentName') %>"></asp:Label>
                                                    <br />
                                                    <asp:Label ID="Label2" runat="server" Text="Adm No  :"></asp:Label>
                                                    <asp:Label ID="lblAdmNo" runat="server" Text="<% #Bind('AdmNo') %>"></asp:Label>
                                                    <br />
                                                    <asp:Label ID="Label3" runat="server" Text="Class   :"></asp:Label>
                                                    <asp:Label ID="lblClass" runat="server" Text="<% #Bind('ClassSection') %>"></asp:Label>
                                                </div>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                                <asp:Button ID="btnAdd" runat="server" Text="Assign" OnClick="btnAdd_Click" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" Height="1px" />
                </asp:GridView>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White"  />
    <EditRowStyle BackColor="#7C6F57" />
    <AlternatingRowStyle BackColor="#1C5E55" />
</asp:GridView>


When i click btnAdd, i want to have the value of lblRoomid.Text.
Please help.

Thanks in anticipation
Faiz.
Posted

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