Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
'Clear the contents of the Label
Me.LabelPostBack.Text = ""
If Not Page.IsPostBack Then
'Bind Master Details
BindData()
Else
For i As Integer = 0 To Me.DataGrid1.Items.Count - 1
'After Postback ID's get lost. Javascript will not work without it,
'so we must set them back.
Me.DataGrid1.Items(i).Cells(0).ID = "CellInfo" + i.ToString()
Next
'If it is a postback that is not from the grid, we have to expand the rows
'the user had expanded before. We have to check first who called this postback
'by checking the Event Target. The reason we check this, is because we don't
'need
'to expand if it is changing the page of the datagrid, or sorting, etc...
If Request("__EVENTTARGET") Is Nothing Then
Return
Else
Dim strEventTarget As String = Request("__EVENTTARGET").ToString().ToLower()
'datagrid1 is the name of the grid. If you modify the grid name,
'make sure to modify this if statement.
If strEventTarget.IndexOf("datagrid1") = -1 Then
If Not Page.IsStartupScriptRegistered("ShowDataJS") Then
Page.RegisterStartupScript("ShowDataJS",
"<script>ShowExpandedDivInfo('" +
Me.txtExpandedDivs.ClientID + "','" +
Me.DataGrid1.ClientID + "');</script>")
End If
End If
End If
End If
End Sub