Save a gridview data which is inside another gridview's Rowdatabound

RadhaKrishnaKiJaya
RadhaKrishnaKiJaya used Ask the Experts™
on
Hi Experts,

I have a gridview. one of its column has s plus sign. When I click the plus sign it makes the other gridview visible . When I click the minus sign it is invisible. Is there anyway I can save the data of the popup gridview in a dataset or a datatable when the minus sign is clicked. I have attached the screenshots.

Thanks in advance.


Code for + and -
----------------------------

 <script  type="text/javascript" src="Jqueries/jquery_nestedGrid.min.js"></script>
     <script type="text/javascript">
         $("[src*=plus]").live("click", function () {
             $(this).closest("tr").after("<tr><td></td><td colspan = '900'>" + $(this).next().html() + "</td></tr>")
             $(this).attr("src", "images/minus.png");
             
         });
         $("[src*=minus]").live("click", function () {
             $(this).attr("src", "images/plus.png");
             $(this).closest("tr").next().remove();
         });
     </script>


Gridview column
---------------------------
  <asp:TemplateField ItemStyle-Width="4%">
                    <ItemTemplate>
                        <asp:image alt = "" style="cursor: pointer;" src="images/plus.png" id="ImgPlusMinus" runat="server" />
                        <asp:Panel ID="pnlOrders" runat="server" Style="display: none">
                            <asp:GridView ID="gvVendors" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid SetLeftMarginChildGrid">
                                <Columns>
                                    <asp:BoundField DataField="VendorID" HeaderText="ID" visible="false" />
                                    <asp:BoundField ItemStyle-Width="300px" DataField="VendorName" HeaderText="Vendor" />
                                    <asp:BoundField ItemStyle-Width="100px" DataField="PartCost" HeaderText="Part Cost" />
                                    <asp:BoundField ItemStyle-Width="200px" DataField="PreferredVendor" HeaderText="Preferred Vendor" />
                                     <asp:TemplateField HeaderText="Qty. Ordered">
                                        <HeaderStyle Width="110px" HorizontalAlign="Left"/>
                                        <ItemStyle Width="50px" HorizontalAlign="Left"/>
                                        <ItemTemplate>
                                            <asp:textbox ID="txtQtyOrdered" runat="server" Width ="100px"></asp:textbox>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </asp:Panel>
                    </ItemTemplate>
                </asp:TemplateField>
Vendor1.png
Vendor2.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kaushal AroraTechnical Analyst

Commented:
Hi RadhaKrishnaKiJaya,

I think one work around for you is to loop the html table in jQuery and save the data in XML format in a public variable declared in code file. You can save the data to a public variable using jQuery/JavaScript. This way you can get that XML string in code file and convert that to DataSet or DataTable. This looping will be done in this function

$("[src*=minus]").live("click", function () 

Open in new window


Hope it helps you.

Regards,
Kaushal A

Author

Commented:
Can you please show me how to do it.

Thanks.
Kaushal AroraTechnical Analyst

Commented:
Yes, I can but for that I would require your code component that is the html of  the grid which is rendered in your case.

Regards,
Kaushal Arora
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Author

Commented:
I already posted the code above.

Thanks.
Kaushal AroraTechnical Analyst

Commented:
Hi,

What I meant was to provide me with the run-time Html of the Grid view so that I need not to write the full code behind logic to fill the grid and get things done for you.

Thanks.
Hi,

Thanks for trying to help me. I changed the program and it is working for me now. Instead of image, I created 2 buttons and making the child grid visible and invisible in the button click. So It is easy to get the values and then I can save it.

  <asp:Button ID ="btnShow" Text="Details" runat= "server" CommandName= "Details" CommandArgument='<%# Container.DataItemIndex%>' />
                        <asp:Button ID ="btnCancel" Text="Save" runat= "server" CommandName= "Cancel" CommandArgument='<%# Container.DataItemIndex%>' Visible="false" />
                        <asp:GridView ID="gvVendors" runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid" Visible ="false" >
                            <Columns>
                                  <asp:TemplateField HeaderText="Vendor" HeaderStyle-HorizontalAlign="left">
                                    <HeaderStyle Width="80px" HorizontalAlign="Left"/>
                                    <ItemStyle Width="80px" HorizontalAlign="Left"/>
                           
                                    <ItemTemplate>
                                            <asp:Label ID="lblVendorID" runat="server" Text='<%#Eval("VendorID")%>'  visible="false">  </asp:Label>
                                            <asp:Label ID="lblVendorName" runat="server" Text='<%#Eval("VendorName")%>' >  </asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>            


                                  <asp:TemplateField HeaderText="Part Cost" HeaderStyle-HorizontalAlign="left">
                                    <HeaderStyle Width="80px" HorizontalAlign="Left"/>
                                    <ItemStyle Width="80px" HorizontalAlign="Left"/>
                           
                                    <ItemTemplate>
                                            <asp:Label ID="lblPartCost" runat="server" Text='<%#Eval("PartCost")%>' >  </asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>

                                 <asp:TemplateField HeaderText="Preferred Vendor" HeaderStyle-HorizontalAlign="left">
                                    <HeaderStyle Width="80px" HorizontalAlign="Left"/>
                                    <ItemStyle Width="80px" HorizontalAlign="Left"/>
                           
                                    <ItemTemplate>
                                            <asp:Label ID="lblPreferredVendor" runat="server" Text='<%#Eval("PreferredVendor")%>' >  </asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>

                                                                       
                               <%-- <asp:BoundField ItemStyle-Width="200px" DataField="PreferredVendor" HeaderText="Preferred Vendor" />--%>
                                <asp:TemplateField HeaderText="Qty. Ordered">
                                    <HeaderStyle Width="200px" HorizontalAlign="Left"/>
                                    <ItemStyle Width="100px" HorizontalAlign="Left"/>
                                    <ItemTemplate>
                                        <asp:textbox ID="txtQtyOrdered" runat="server" Width ="60px"></asp:textbox>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

Author

Commented:
This solution is working for me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial