Hello.
I have a DataList as (PARENT) and a GridView as (CHILD)l. The user should see only ONE expanded division of CHILD data at a time. So, I have placed the GridView between <div></div> tag to be toggled ON/OFF. That is, I have to collapse any expanded division in order to show new one. The DataList has a button to Expand or Collapse the display.
The displayed DataList items will NOT be reloaded from server upon child data display. Only the child data will be retrieved from db for display. Retrieving only child data makes me have no access to test all displayed DataList items to collapse the previous displayed division (e.i using a loop such as For Each DL_item In DataList1.Items)
I have used two approaches, none of them worked!!
1st approach. Server-side & Client side coding:
I am using the following server-side coding to show a hidden division. This is done via SelectedIndexChanged.
'In selected item, find the division and expand it.
div = DataList1.Items(DataList1.SelectedIndex).FindControl("GVDiv")
div.Style.Item("DISPLAY") = "block"
And, in a loop, I'm using the following client-side script to collapse all shown division. Note that a client-side coding will take care of expanding the needed division.
document.getElementById(DivName).style.display = 'none';
The problem is: Server-side coding does NOT see new changes that the previous division was collapsed!!
So, how to make sever-side coding to see that all divisions were collapsed by client-side script?
2nd approach. Only Server-side coding:
I have stored the ID of the expanded division in a hidden label and then used that ID for collapsing the div.
This code via SelectedIndexChanged.
Dim oBtnExpnd As Button
Dim oExp As Button
Dim div As HtmlGenericControl
oBtnExpnd = DataList1.Items(DataList1.SelectedIndex).FindControl("btnExpand")
oExp = DataList1.Items(DataList1.SelectedIndex).FindControl("btnExpand")
div = DataList1.Items(DataList1.SelectedIndex).FindControl("My_GV_Div")
If oExp.Text = "+" And div.Style.Item("DISPLAY") = "none" Then
div.Style.Item("DISPLAY") = "block" 'displaying div is working fine to display child data.
ShowDetails(strConnection) 'display child data at selected division.
Dim StoredDivID As New Label
StoredDivID = CType(Me.FindControl("IDDiv"), Label) 'find IDDiv label.
If (StoredDivID.Text <> "none") Then 'default ID of hidden label is none.
Dim NewDiv As New HtmlGenericControl("div") 'create new division
NewDiv.ID = StoredDivID.Text 'new created DIV will have ID of previous expanded division.
NewDiv.Style.Item("DISPLAY") = "none" 'hide previous div. (== did NOT work!!)
StoredDivID.Text = div.ClientID 'store selected divsion ID into hidden label.
Else
StoredDivID.Text = div.ClientID 'store selected divsion ID into hidden label.
End If
oBtnExpnd.Text = "-"
ElseIf oExp.Text = "-" And div.Style.Item("DISPLAY") = "block" Then
div.Style.Item("DISPLAY") = "none" 'works fine sicne I am at the same seleced index.
oBtnExpnd.Text = "+"
End If
Any ideas how I can correct the problem?
Thanks