Solved

ASP.Net parent child gridview example - almost works

Posted on 2014-04-08
8
2,784 Views
Last Modified: 2014-04-09
hi
I need parent/child gridview WITH postback.  I'm trying code at following
http://aspnetexampless.blogspot.co.uk/2012/05/editing-child-gridview-in-nested.html

it created page http://www.dotnetspeaks.com/LiveDemos/ASP.NET/GridView/EditingNestedGridView.aspx
which does what I need

however I cannot get it to work. errors such as
-error with "btnExpandRow" not declared.
-GridViewChildPageIndex not declared

please resolve, thank-you

ASPX here:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestParentChildWithPostback.aspx.vb" Inherits="Testing_TestParentChildWithPostback" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .modalBackground {
            background-color: Gray;
            filter: alpha(opacity=80);
            opacity: 0.5;
        }

        .ModalWindow {
            border: solid 1px #c0c0c0;
            background: #f0f0f0;
            padding: 0px 10px 10px 10px;
            position: absolute;
            top: -1000px;
        }
    </style>
</head>
<body>
        <script type="text/javascript">
        function OpenTable(trRow, imgId, ID) {
            document.getElementById('<%=hidRowIndex.ClientID %>').value = ID;
            document.getElementById('<%=hidRowId.ClientID %>').value = trRow;
            document.getElementById('<%=hidImgId.ClientID %>').value = imgId;
            __doPostBack("<%=btnExpandRow.ClientID%>", "");

        }
    </script>
    <script type="text/javascript">
        // Reference of PageRequestManager.
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);
        // Async postback starts.
        function InitializeRequest(sender, args) {
            var modalPopupBehavior = $find('<%=ModalPopupExtender1.ClientID %>');
                 modalPopupBehavior.show();
             }
             // Async postback ends.
             function EndRequest(sender, args) {
                 var modalPopupBehavior = $find('<%=ModalPopupExtender1.ClientID %>');
                 modalPopupBehavior.hide();
             }
    </script>

    <form runat="server" id="theForm">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>

   <asp:UpdatePanel runat="server" ID="updTest" UpdateMode="Conditional">
      <ContentTemplate>
            <asp:GridView ID="gvParent" runat="server" AutoGenerateColumns="False"  CellPadding="4" ForeColor="#333333" ShowHeader="True" DataKeyNames="EmployeeId">
                  <Columns>
                        <asp:TemplateField ItemStyle-Width="20px">
                              <ItemTemplate>
                                    <asp:Image runat="server" ID="img1" ImageUrl="images/Collapse.GIF" />
                                                                    <asp:Button runat="server" ID="btnExpandRow" Text="the button!" />

                              </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="Employee Id" DataField="EmployeeId">
                              <ItemStyle HorizontalAlign="Center" Width="160px" />
                        </asp:BoundField>
                        <asp:BoundField HeaderText="Employee Name" DataField="EmployeeName">
                              <ItemStyle HorizontalAlign="Center" Width="160px" />
                        </asp:BoundField>
                        <asp:BoundField HeaderText="Designation" DataField="Designation">
                              <ItemStyle HorizontalAlign="Center" Width="160px" />
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="Location">
                              <ItemTemplate>
                                    <asp:Label ID="lblEmpName" runat="server" Text='<%# Eval("Location")%>'>
                                    </asp:Label>
                                    <asp:Literal runat="server" ID="lit1" Text="</td><tr id=''trCollapseGrid'' style=''display:none'' ><td colspan=''5''>" />
                                    <asp:GridView ID="gvChild" AutoGenerateColumns="False" runat="server" EnableViewState="False" DataKeyNames="EmployeeId" ForeColor="#333333" PageSize="2" AllowPaging="True" OnPageIndexChanging="gvChild_PageIndexChanging" OnRowCancelingEdit="gvChild_RowCancelingEdit" OnRowDeleting="gvChild_RowDeleting" OnRowEditing="gvChild_RowEditing" OnRowUpdating="gvChild_RowUpdating">
                                          <RowStyle BackColor="#EFF3FB" />
                                          <AlternatingRowStyle BackColor="White" />
                                          <Columns>
                                                <asp:BoundField HeaderText="Skill ID" DataField="SkillID" ReadOnly="True">
                                                      <ItemStyle HorizontalAlign="Center" Width="80px" />
                                                </asp:BoundField>
                                                <asp:BoundField HeaderText="Employee Id" DataField="EmployeeId" ReadOnly="True">
                                                      <ItemStyle HorizontalAlign="Center" Width="100px" />
                                                </asp:BoundField>
                                                <asp:TemplateField HeaderText="SkillSet">
                                                      <ItemStyle HorizontalAlign="Center" Width="100px" />
                                                      <ItemTemplate>
                                                            <%# Eval("SkillSet")%>
                                                      </ItemTemplate>
                                                      <EditItemTemplate>
                                                            <asp:TextBox ID="txtEditSkillSet" runat="server" Text='<%# Eval("SkillSet")%>' Width="100px"></asp:TextBox>
                                                      </EditItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Remarks">
                                                      <ItemStyle HorizontalAlign="Center" Width="100px" />
                                                      <ItemTemplate>
                                                            <%# Eval("Remarks")%>
                                                      </ItemTemplate>
                                                       <EditItemTemplate>
                                                            <asp:TextBox ID="txtEditRemarks" runat="server" Text='<%# Eval("Remarks")%>' Width="100px"></asp:TextBox>
                                                      </EditItemTemplate>
                                                </asp:TemplateField>
                                                <asp:CommandField ButtonType="Button" EditText="Edit" HeaderText="Edit" ShowEditButton="true" />
                                                <asp:CommandField ButtonType="Button" DeleteText="Delete" HeaderText="Delete" ShowDeleteButton="true" />
                                          </Columns>
                                          <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                    </asp:GridView>
                                    <asp:Literal runat="server" ID="lit2" Text="</td></tr>" />
                              </ItemTemplate>
                        </asp:TemplateField>
                  </Columns>
                  <RowStyle BackColor="#EFF3FB" />
                  <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
            <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="hidProcessing" PopupControlID="panEdit" BackgroundCssClass="modalBackground" PopupDragHandleControlID="panEdit">
            </cc1:ModalPopupExtender>
            <asp:Panel ID="panEdit" runat="server" CssClass="ModalWindow">
                  <div style="background-color: White">
                        <img src="images/processing.gif" alt="Processing" />
                        Processing......
                  </div>
            </asp:Panel>
            <asp:HiddenField ID="hidProcessing" runat="server" />
      </ContentTemplate>
      <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnExpandRow" EventName="Click" />
      </Triggers>
</asp:UpdatePanel>

    <p>
        &nbsp;
    </p>
    <p>
        &nbsp;
    </p>
    <p>
        &nbsp;
    </p>

    <asp:Button ID="btnTest" runat="server" Style="display: none" />
    <asp:HiddenField ID="hidRowId" runat="server" />
    <asp:HiddenField ID="hidImgId" runat="server" />
    <asp:HiddenField ID="hidRowIndex" runat="server" />
</form>
</body>
</html>

Open in new window


VB.Net here:
    Private Function GetParentTableData() As DataTable
        Dim table As New DataTable()
        table.Columns.Add("EmployeeId", GetType(String))
        table.Columns.Add("EmployeeName", GetType(String))
        table.Columns.Add("Designation", GetType(String))
        table.Columns.Add("Location", GetType(String))

        table.Rows.Add(100, "Andy", "S/W Engg", "NY")
        table.Rows.Add(200, "James", "S/W Engg", "NJ")
        table.Rows.Add(300, "Ramesh", "Sr. S/W Engg", "Bangalore")
        table.Rows.Add(400, "George", "Architect", "London")
        table.Rows.Add(500, "Lisa", "Manager", "Washington")
        Return table
    End Function



    Private Function GetChildTableData() As DataTable
        Dim table As New DataTable()
        table.Columns.Add("SkillID", GetType(String))
        table.Columns.Add("EmployeeId", GetType(String))
        table.Columns.Add("SkillSet", GetType(String))
        table.Columns.Add("Remarks", GetType(String))
        table.Rows.Add("1", "100", "ASP.NET", "Remarks1")
        table.Rows.Add("2", "100", "SQL", "Remarks2")
        table.Rows.Add("1", "200", "ASP.NET", "Remarks1")
        table.Rows.Add("2", "200", "SQL", "Remarks2")
        table.Rows.Add("3", "200", "WCF", "Remarks3")
        table.Rows.Add("4", "300", "PHP", "Remarks1")
        table.Rows.Add("5", "300", "Oracle", "Remarks2")
        table.Rows.Add("6", "300", "Javascipt", "Remarks3")
        table.Rows.Add("7", "400", "J2EE", "Remarks1")
        table.Rows.Add("5", "400", "Oracle", "Remarks2")
        table.Rows.Add("8", "400", "Struts", "Remarks3")
        table.Rows.Add("9", "500", "Estimation", "Remarks1")
        table.Rows.Add("10", "500", "Project Plan", "Remarks2")
        table.Rows.Add("11", "500", "Resource Loading", "Remarks3")
        table.Rows.Add("12", "500", "Resource allocation", "Remarks4")
        Return table
    End Function

    Protected Sub btnExpandRow_Click(sender As Object, e As EventArgs)
        Dim dtParentData As DataTable = GetParentTableData()
        gvParent.DataSource = dtParentData
        gvParent.DataBind()
    End Sub

    Protected Sub gvParent_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim strID As String = gvParent.DataKeys(e.Row.RowIndex).Value.ToString()
            Dim img As Image = DirectCast(e.Row.Cells(0).FindControl("img1"), Image)
            Dim ltrl As Literal = DirectCast(e.Row.FindControl("lit1"), Literal)
            ltrl.Text = ltrl.Text.Replace("trCollapseGrid", "trCollapseGrid" & e.Row.RowIndex.ToString())
            Dim str As String = "trCollapseGrid" & e.Row.RowIndex.ToString()
            e.Row.Cells(0).Attributes.Add("OnClick", ("return OpenTable(''" & str & "'',''") + img.ClientID & "'',''" & strID & "'')")
            e.Row.Cells(0).RowSpan = 1
            Dim gvChild As System.Web.UI.WebControls.GridView = DirectCast(e.Row.FindControl("gvChild"), System.Web.UI.WebControls.GridView)
            If Session("ChildPageIndex") IsNot Nothing Then
                Dim dtPageIndex As DataTable = DirectCast(Session("ChildPageIndex"), DataTable)
                gvChild.PageIndex = Convert.ToInt16(dtPageIndex.Rows(e.Row.RowIndex)(0))
            End If
            If hidRowIndex.Value.Equals(strID) Then
                BindChildgvwChildView(strID, gvChild)
                If Not ClientScript.IsStartupScriptRegistered("ChildGrid") Then
                    Dim javScript As String = "document.getElementById(''" + hidRowId.Value & "'').style.display = '';"
                    javScript = (javScript & "document.getElementById(''") + hidImgId.Value & "'').src = ''images/Expand.gif'';"
                    ScriptManager.RegisterStartupScript(Page, Page.[GetType](), "ChildGrid", javScript, True)
                End If
            End If
        End If
    End Sub
    Private Sub BindChildgvwChildView(empId As String, gvChild As System.Web.UI.WebControls.GridView)
        Dim dtChildTable As DataTable = GetChildTableData()
        Dim dtCloneChildTable As DataTable = dtChildTable.Clone()
        Dim gvChildRows As DataRow() = dtChildTable.[Select]("EmployeeId = " & empId)
        For Each gvChildRow As DataRow In gvChildRows
            dtCloneChildTable.ImportRow(gvChildRow)
        Next
        gvChild.DataSource = dtCloneChildTable
        gvChild.DataBind()
    End Sub
    Protected Sub gvChild_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
        Dim gvwChild As System.Web.UI.WebControls.GridView = DirectCast(sender, System.Web.UI.WebControls.GridView)
        Dim gvRowParent As GridViewRow = TryCast(DirectCast(sender, System.Web.UI.WebControls.GridView).Parent.Parent, GridViewRow)
        gvwChild.PageIndex = e.NewPageIndex
        If Session("ChildPageIndex") IsNot Nothing Then
            Dim dtPageIndex As DataTable = DirectCast(Session("ChildPageIndex"), DataTable)
            dtPageIndex.Rows(gvRowParent.RowIndex)(0) = e.NewPageIndex
        End If
        KeepExpanded(gvwChild, sender)
    End Sub
    Protected Sub KeepExpanded(gvwChild As System.Web.UI.WebControls.GridView, sender As Object)
        Dim gvRowParent As GridViewRow = TryCast(DirectCast(sender, System.Web.UI.WebControls.GridView).Parent.Parent, GridViewRow)
        BindChildgvwChildView(gvParent.DataKeys(gvRowParent.RowIndex).Value.ToString(), gvwChild)
        If Not ClientScript.IsStartupScriptRegistered("ChildGridIndex") Then
            ScriptManager.RegisterStartupScript(Page, Page.[GetType](), "ChildGridIndex", "document.getElementById(''" + hidRowId.Value & "'').style.display = '';", True)
        End If
    End Sub
    Protected Sub gvChild_RowEditing(sender As Object, e As GridViewEditEventArgs)
        Dim gvwChild As System.Web.UI.WebControls.GridView = DirectCast(sender, System.Web.UI.WebControls.GridView)
        gvwChild.EditIndex = e.NewEditIndex
        KeepExpanded(gvwChild, sender)
    End Sub

    Protected Sub gvChild_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
        Dim gvwChild As System.Web.UI.WebControls.GridView = DirectCast(sender, System.Web.UI.WebControls.GridView)
        Dim txtRemarks As TextBox = DirectCast(gvwChild.Rows(e.RowIndex).FindControl("txtEditRemarks"), TextBox)
        Dim txtSkillSet As TextBox = DirectCast(gvwChild.Rows(e.RowIndex).FindControl("txtEditSkillSet"), TextBox)
        'Code to update table
        gvwChild.EditIndex = -1
        KeepExpanded(gvwChild, sender)
    End Sub
    Protected Sub gvChild_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
        Dim gvwChild As System.Web.UI.WebControls.GridView = DirectCast(sender, System.Web.UI.WebControls.GridView)
        'Code to delete data from table
        KeepExpanded(gvwChild, sender)
    End Sub
    Protected Sub gvChild_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs)
        Dim gvwChild As System.Web.UI.WebControls.GridView = DirectCast(sender, System.Web.UI.WebControls.GridView)
        gvwChild.EditIndex = -1
        KeepExpanded(gvwChild, sender)
    End Sub


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim dtParentData As DataTable = GetParentTableData()
            gvParent.DataSource = dtParentData
            gvParent.DataBind()
            GridViewChildPageIndex()
        End If
    End Sub

Open in new window

0
Comment
Question by:rwallacej
  • 5
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
dejaanbu earned 500 total points
ID: 39987949
you don't have definition for the method "GridViewChildPageIndex". but you are calling it on page_load , and hence the error.

the tutorial link you showed doesnt have the definition for that method too...

so, follow this or this , (yes it is the same example!). it has the definition.. hope you will get rid of both errors by following this ...
0
 

Author Comment

by:rwallacej
ID: 39988318
thanks for help. btnTest has no code for it though

the page works now like this

InitializeRequest
btnTest_Click
EndRequest

BUT
btnTest event doesn't bind the data (so I simply get no data in child )
0
 

Author Comment

by:rwallacej
ID: 39988324
I used some dummy data for purpose of this not the connection (but with same fields)

I have added a btnTest  event and looked at gvParent.selectedrow etc and this is nothing
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 14

Expert Comment

by:dejaanbu
ID: 39988832
i'm not understanding!..what's the purpose of btnTest here? the tutorial link which i posted doesnt have btnTest...can you elaborate?
0
 

Author Comment

by:rwallacej
ID: 39988953
see <asp:Button ID="btnTest" runat="server" OnClick="btnTest_Click" Style="display: none" />
it's hidden buton in postback
0
 

Author Closing Comment

by:rwallacej
ID: 39989122
I had converted from C# to VB.net wrong. for purpose of others help here is VB.net
0
 

Author Comment

by:rwallacej
ID: 39989125
Imports System.Data

Partial Class LazyLoadTest
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim dtParentData As DataTable = GetParentTableData()
            gvParent.DataSource = dtParentData
            gvParent.DataBind()
            GridViewChildPageIndex()
        End If
    End Sub

    Protected Sub btnTest_Click(sender As Object, e As EventArgs)
        Dim dtParentData As DataTable = GetParentTableData()
        gvParent.DataSource = dtParentData
        gvParent.DataBind()
    End Sub


    Private Function GetParentTableData() As DataTable
        Dim table As New DataTable()
        table.Columns.Add("EmployeeId", GetType(String))
        table.Columns.Add("EmployeeName", GetType(String))
        table.Columns.Add("Designation", GetType(String))
        table.Columns.Add("Location", GetType(String))

        table.Rows.Add(100, "Andy", "S/W Engg", "NY")
        table.Rows.Add(200, "James", "S/W Engg", "NJ")
        table.Rows.Add(300, "Ramesh", "Sr. S/W Engg", "Bangalore")
        table.Rows.Add(400, "George", "Architect", "London")
        table.Rows.Add(500, "Lisa", "Manager", "Washington")
        table.Rows.Add(600, "Lisa", "Manager", "Washington")
        Return table

    End Function

    Private Function GetChildTableData() As DataTable
        Dim table As New DataTable()
        table.Columns.Add("SkillID", GetType(String))
        table.Columns.Add("EmployeeId", GetType(String))
        table.Columns.Add("SkillSet", GetType(String))
        table.Columns.Add("Remarks", GetType(String))

        table.Rows.Add("1", "100", "ASP.NET", "Remarks1")
        table.Rows.Add("2", "100", "SQL", "Remarks2")

        table.Rows.Add("1", "200", "ASP.NET", "Remarks1")
        table.Rows.Add("2", "200", "SQL", "Remarks2")
        table.Rows.Add("3", "200", "WCF", "Remarks3")

        table.Rows.Add("4", "300", "PHP", "Remarks1")
        table.Rows.Add("5", "300", "Oracle", "Remarks20")
        table.Rows.Add("6", "300", "Javascipt", "Remarks3")

        table.Rows.Add("7", "400", "J2EE", "Remarks1")
        table.Rows.Add("5", "400", "Oracle", "Remarks2")
        table.Rows.Add("8", "400", "Struts", "Remarks3")

        table.Rows.Add("9", "500", "Estimation", "Remarks1")
        table.Rows.Add("10", "500", "Project Plan", "Remarks2")
        table.Rows.Add("11", "500", "Resource Loading", "Remarks3")
        table.Rows.Add("12", "500", "Resource allocation", "Remarks4")
        table.Rows.Add("17", "500", "Resource allocation", "Remarks5")



        table.Rows.Add("13", "600", "Estimation", "Remarks1")
        table.Rows.Add("14", "600", "Project Plan", "Remarks2")
        table.Rows.Add("15", "600", "Resource Loading", "Remarks3")
        table.Rows.Add("16", "600", "Resource allocation", "Remarks4")

        Return table

    End Function


    Protected Sub gvParent_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim strID As String = gvParent.DataKeys(e.Row.RowIndex).Value.ToString()
            Dim img As Image = DirectCast(e.Row.Cells(0).FindControl("img1"), Image)
            Dim ltrl As Literal = DirectCast(e.Row.FindControl("lit1"), Literal)
            ltrl.Text = ltrl.Text.Replace("trCollapseGrid", "trCollapseGrid" & e.Row.RowIndex.ToString())
            Dim str As String = "trCollapseGrid" & e.Row.RowIndex.ToString()
            e.Row.Cells(0).Attributes.Add("OnClick", ("return OpenTable('" & str & "','") + img.ClientID & "','" & strID & "')")
            e.Row.Cells(0).RowSpan = 1
            Dim gvChild As System.Web.UI.WebControls.GridView = DirectCast(e.Row.FindControl("gvChild"), System.Web.UI.WebControls.GridView)

            If Session("ChildPageIndex") IsNot Nothing Then
                Dim dtPageIndex As DataTable = DirectCast(Session("ChildPageIndex"), DataTable)

                gvChild.PageIndex = Convert.ToInt16(dtPageIndex.Rows(e.Row.RowIndex)(0))
            End If
            If hidRowIndex.Value.Equals(strID) Then
                BindChildGrdView(strID, gvChild)
                If Not ClientScript.IsStartupScriptRegistered("ChildGrid") Then
                    Dim javScript As String = "document.getElementById('" + hidRowId.Value & "').style.display = '';"
                    javScript = (javScript & "document.getElementById('") + hidImgId.Value & "').src  = 'images/Expand.gif';"
                    ScriptManager.RegisterStartupScript(Page, Page.[GetType](), "ChildGrid", javScript, True)
                End If

            End If
        End If
    End Sub

    Protected Sub gvChild_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
        Dim gvwChild As System.Web.UI.WebControls.GridView = DirectCast(sender, System.Web.UI.WebControls.GridView)
        Dim gvRowParent As GridViewRow = TryCast(DirectCast(sender, System.Web.UI.WebControls.GridView).Parent.Parent, GridViewRow)

        gvwChild.PageIndex = e.NewPageIndex
        If Session("ChildPageIndex") IsNot Nothing Then
            Dim dtPageIndex As DataTable = DirectCast(Session("ChildPageIndex"), DataTable)
            dtPageIndex.Rows(gvRowParent.RowIndex)(0) = e.NewPageIndex
        End If
        BindChildGrdView(gvParent.DataKeys(gvRowParent.RowIndex).Value.ToString(), gvwChild)

        If Not ClientScript.IsStartupScriptRegistered("ChildGridIndex") Then
            ScriptManager.RegisterStartupScript(Page, Page.[GetType](), "ChildGridIndex", "document.getElementById('" + hidRowId.Value & "').style.display = '';", True)
        End If

    End Sub


    Private Sub BindChildGrdView(empId As String, gvChild As System.Web.UI.WebControls.GridView)
        Dim dtChildTable As DataTable = GetChildTableData()
        Dim dtCloneChildTable As DataTable = dtChildTable.Clone()


        Dim gvChildRows As DataRow() = dtChildTable.[Select]("EmployeeId = " & empId)
        For Each gvChildRow As DataRow In gvChildRows
            dtCloneChildTable.ImportRow(gvChildRow)
        Next
        gvChild.DataSource = dtCloneChildTable
        gvChild.DataBind()
    End Sub

    Private Sub GridViewChildPageIndex()
        Dim dtPageIndex As New DataTable()
        dtPageIndex.Columns.Add("PageIndex", GetType(Integer))
        For i As Integer = 0 To gvParent.Rows.Count - 1
            dtPageIndex.Rows.Add("0")
        Next
        Session("ChildPageIndex") = dtPageIndex
    End Sub


End Class




<%@ Page Language="VB" AutoEventWireup="false" CodeFile="LazyLoadTest.aspx.vb"
    Inherits="LazyLoadTest"
      %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
    TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        .modalBackground
        {
            background-color:Gray;
            filter: alpha(opacity=80);
            opacity: 0.5;
        }
        .ModalWindow
        {
            border: solid 1px #c0c0c0;
            background: #f0f0f0;
            padding: 0px 10px 10px 10px;
            position: absolute;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel runat="server" ID="updTest" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:GridView ID="gvParent" runat="server" AutoGenerateColumns="False" OnRowDataBound="gvParent_RowDataBound"
                    CellPadding="4" ForeColor="#333333" ShowHeader="True" DataKeyNames="EmployeeId">
                    <Columns>
                        <asp:TemplateField ItemStyle-Width="20px">
                            <ItemTemplate>
                                <asp:Image runat="server" ID="img1" ImageUrl="images/Collapse.GIF" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="Employee Id" DataField="EmployeeId">
                            <ItemStyle HorizontalAlign="Center" Width="140px" />
                        </asp:BoundField>
                        <asp:BoundField HeaderText="Employee Name" DataField="EmployeeName">
                            <ItemStyle HorizontalAlign="Center" Width="140px" />
                        </asp:BoundField>
                        <asp:BoundField HeaderText="Designation" DataField="Designation">
                            <ItemStyle HorizontalAlign="Center" Width="140px" />
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="Location">
                            <ItemTemplate>
                                <asp:Label ID="lblEmpName" runat="server" Text='<%# Eval("Location")%>'></asp:Label>
                                <asp:Literal runat="server" ID="lit1" Text="</td><tr id='trCollapseGrid' style='display:none' ><td colspan='5'>" />
                                <asp:GridView ID="gvChild" AutoGenerateColumns="False" runat="server" EnableViewState="False"
                                    DataKeyNames="EmployeeId" ForeColor="#333333"
                                    PageSize="90" AllowPaging="True"
                                    OnPageIndexChanging="gvChild_PageIndexChanging">
                                    <RowStyle BackColor="#EFF3FB" />
                                    <AlternatingRowStyle BackColor="White" />
                                    <Columns>
                                        <asp:BoundField HeaderText="Skill ID" DataField="SkillID">
                                            <ItemStyle HorizontalAlign="Center" Width="80px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Employee Id" DataField="EmployeeId">
                                            <ItemStyle HorizontalAlign="Center" Width="100px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Skill Set" DataField="SkillSet">
                                            <ItemStyle HorizontalAlign="Center" Width="110px" />
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Remarks" DataField="Remarks">
                                            <ItemStyle HorizontalAlign="Center" Width="245px" />
                                        </asp:BoundField>
                                    </Columns>
                                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                </asp:GridView>
                                <asp:Literal runat="server" ID="lit2" Text="</td></tr>" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <RowStyle BackColor="#EFF3FB" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="hidProcessing"
                    PopupControlID="panEdit" BackgroundCssClass="modalBackground" PopupDragHandleControlID="panEdit">
                </ajaxToolkit:ModalPopupExtender>
                <asp:Panel ID="panEdit" runat="server" CssClass="ModalWindow">
                    <div style="background-color:White">
                        <img src="images/processing.gif" alt="Processing" />
                        Processing......
                    </div>
                </asp:Panel>
                <asp:HiddenField ID="hidProcessing" runat="server" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnTest" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
        <asp:Button ID="btnTest" runat="server" OnClick="btnTest_Click" Style="display: none" />        
        <asp:HiddenField ID="hidRowId" runat="server" />
        <asp:HiddenField ID="hidImgId" runat="server" />
        <asp:HiddenField ID="hidRowIndex" runat="server" />

    </div>
    </form>
</body>
</html>

<script language="javascript" type="text/javascript">
    function OpenTable(trRow, imgId, ID) {
        document.getElementById('<%=hidRowIndex.ClientID %>').value = ID;
        document.getElementById('<%=hidRowId.ClientID %>').value = trRow;
        document.getElementById('<%=hidImgId.ClientID %>').value = imgId;
        __doPostBack("<%=btnTest.ClientID%>", "");

    }

</script>

<script language="javascript" type="text/javascript">



    // Reference of PageRequestManager.
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);

    // Async postback starts.
    function InitializeRequest(sender, args) {
        var modalPopupBehavior = $find('<%=ModalPopupExtender1.ClientID %>');
        modalPopupBehavior.show();
    }

    // Async postback ends.
    function EndRequest(sender, args) {
        var modalPopupBehavior = $find('<%=ModalPopupExtender1.ClientID %>');
        modalPopupBehavior.hide();
    }

</script>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now