locked
Repeating Panel with Gridview in vb.net RRS feed

  • Question

  • User-1578974752 posted


    I have a Panel (PanelA) in VB.NET,
    This panel is having 2 grid view (which is allowed to edit) with different tables.

    Once I click Add Panel button,I want to create new panel(PanelB)  with these 2 grid views

    like that ,how many times user click Add Panel button,that many times new panel must be created with 2 editable gridviews.

    Is this possible in vb.net.How to show new panel with 2 gridviews on each button click?. Appreciate the help

    Tuesday, February 12, 2019 10:01 AM

Answers

  • User475983607 posted


    I have a Panel (PanelA) in VB.NET,
    This panel is having 2 grid view (which is allowed to edit) with different tables.

    Once I click Add Panel button,I want to create new panel(PanelB)  with these 2 grid views

    like that ,how many times user click Add Panel button,that many times new panel must be created with 2 editable gridviews.

    Is this possible in vb.net.How to show new panel with 2 gridviews on each button click?. Appreciate the help

    Sure, the common Web Forms Approach is using a DataBound control.  A Repeater should work great.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 12, 2019 3:34 PM
  • User-1174608757 posted

    Hi shsu,

    According to your description, I have made a sample here.It will be very simpleto accomplish your requirement by using  .clone() in Jquery . Here is the demo , I hope it could help you.

    aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function () {
                $("#Button1").click(function () {
                    $("#Panel1").clone().appendTo("#form1")
                //clone the content of panel
    
    
                })
    
    
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <input id="Button1" type="button" value="add panel" />
                <asp:Panel ID="Panel1" runat="server">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="true"></asp:GridView>
                    <asp:GridView ID="GridView2" runat="server" AutoGenerateEditButton="true"></asp:GridView>
                </asp:Panel>
            </div>
        </form>
    </body>
    </html>
    

    aspx.cs

    Public Class Gridview
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    // bind Gridview1 and bind Gridview2 Dim sql1 = "select * from db" GridView1.DataSource = SqlHelper.ExecuteDataTable(sql1) GridView1.DataBind() Dim sql2 = "select * from test" GridView2.DataSource = SqlHelper.ExecuteDataTable(sql2) GridView2.DataBind() End Sub End Class

    It shows as below:

    Best Regards

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 13, 2019 3:06 AM

All replies

  • User475983607 posted


    I have a Panel (PanelA) in VB.NET,
    This panel is having 2 grid view (which is allowed to edit) with different tables.

    Once I click Add Panel button,I want to create new panel(PanelB)  with these 2 grid views

    like that ,how many times user click Add Panel button,that many times new panel must be created with 2 editable gridviews.

    Is this possible in vb.net.How to show new panel with 2 gridviews on each button click?. Appreciate the help

    Sure, the common Web Forms Approach is using a DataBound control.  A Repeater should work great.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 12, 2019 3:34 PM
  • User-1174608757 posted

    Hi shsu,

    According to your description, I have made a sample here.It will be very simpleto accomplish your requirement by using  .clone() in Jquery . Here is the demo , I hope it could help you.

    aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function () {
                $("#Button1").click(function () {
                    $("#Panel1").clone().appendTo("#form1")
                //clone the content of panel
    
    
                })
    
    
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <input id="Button1" type="button" value="add panel" />
                <asp:Panel ID="Panel1" runat="server">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="true"></asp:GridView>
                    <asp:GridView ID="GridView2" runat="server" AutoGenerateEditButton="true"></asp:GridView>
                </asp:Panel>
            </div>
        </form>
    </body>
    </html>
    

    aspx.cs

    Public Class Gridview
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    // bind Gridview1 and bind Gridview2 Dim sql1 = "select * from db" GridView1.DataSource = SqlHelper.ExecuteDataTable(sql1) GridView1.DataBind() Dim sql2 = "select * from test" GridView2.DataSource = SqlHelper.ExecuteDataTable(sql2) GridView2.DataBind() End Sub End Class

    It shows as below:

    Best Regards

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 13, 2019 3:06 AM
  • User-1578974752 posted

    Thanks Mgebhard and Wei Zhang


    Some issues I am facing in the Clone,is that:

    For the 2 grid views ,I have Insert button with few text box under the grid view so that upon click insert statement will work. Which will insert the values in to the database. One Add panel button is also there for clone purpose


     These 2 grid views will be empty at first showing only the header.User will insert the values from the textboxes placed below gridview  and click Insert button.then user will click Add panel.

    If add panel is clicked, a new panel with 2 empty gridviews must show just with the header, so that user can insert values in to the table.(using textbox). is this possible

    values can not be cloned. Now once I click insert button again for the second clone ,first panel is only visible and all other is disappearing.

    Will using repeater solve the issue, if so please explain.Appreciate the help.

    Thursday, February 14, 2019 6:01 AM