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

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
RadhaKrishnaKiJayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kaushal AroraTechnical AnalystCommented:
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
RadhaKrishnaKiJayaAuthor Commented:
Can you please show me how to do it.

Thanks.
Kaushal AroraTechnical AnalystCommented:
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
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

RadhaKrishnaKiJayaAuthor Commented:
I already posted the code above.

Thanks.
Kaushal AroraTechnical AnalystCommented:
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.
RadhaKrishnaKiJayaAuthor Commented:
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>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadhaKrishnaKiJayaAuthor Commented:
This solution is working for me.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.