TrialUser
asked on
disable all checkboxes inside a nested datalist control when one checkbox inside the datalist is clicked
I have a datalistparent and a datalistchild . Inside the datalistchild itemtemplate, I have checkboxes. When the user clicks on a checkbox then all checkboxes inside that datalistchild should be disabled. all in server side code. I have attached the html and .vb code. Please help. Thanks
Protected Sub Value_Clicked(ByVal sender As Object, ByVal e As System.EventArgs)
Dim chk As CheckBox = DirectCast(sender, CheckBox)
Dim intValueID As Integer = DirectCast(chk.Parent.Find Control("l blAttribut eValueID") , Label).Text
Dim intNameID As Integer = DirectCast(chk.Parent.Find Control("l blAttrName ID"), Label).Text
If chk.Checked Then
AddNavigationProductFilter (intNameID , intValueID, True)
'here diable all checkboxes in this particular item template (dlAttributeValues)
Else
AddNavigationProductFilter (intNameID , intValueID, False)
'here enable all checkboxes in this particular item template (dlAttributeValues)
End If
BindProductFinderItems()
End Sub
<div class="Attributes">
<asp:DataList ID="dlAttributes" runat="server" RepeatDirection="Horizonta l" RepeatColumns="3" Width="100%">
<ItemStyle Width="33.3%"/>
<ItemTemplate>
<asp:Label ID="lblAttributeNameID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container. DataItem, "ID")%>'></asp:Label>
<span style="color:#58595B;font- size:14px; font-weigh t:bold;">< %# DataBinder.Eval(Container. DataItem, "ShortName")%></span>
<div style="height:100px;overfl ow:auto; border: 1px solid #CACACA;margin:10px 10px 10px 0px;padding:10px;">
<asp:DataList ID="dlAttributeValues" runat="server">
<ItemTemplate>
<asp:Label ID="lblAttrNameID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container. DataItem, "AttributeNameID")%>'></as p:Label>
<asp:Label ID="lblAttributeValueID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container. DataItem, "AttributeValueID")%>'></a sp:Label>
<asp:checkbox ID="chkValue" runat="server" Text='<%# DataBinder.Eval(Container. DataItem," AttributeV alue")%>' AutoPostBack="true" OnCheckedChanged="Value_Cl icked"/>
</ItemTemplate>
</asp:DataList>
</div>
</ItemTemplate>
</asp:DataList>
</div>
Protected Sub Value_Clicked(ByVal sender As Object, ByVal e As System.EventArgs)
Dim chk As CheckBox = DirectCast(sender, CheckBox)
Dim intValueID As Integer = DirectCast(chk.Parent.Find
Dim intNameID As Integer = DirectCast(chk.Parent.Find
If chk.Checked Then
AddNavigationProductFilter
'here diable all checkboxes in this particular item template (dlAttributeValues)
Else
AddNavigationProductFilter
'here enable all checkboxes in this particular item template (dlAttributeValues)
End If
BindProductFinderItems()
End Sub
<div class="Attributes">
<asp:DataList ID="dlAttributes" runat="server" RepeatDirection="Horizonta
<ItemStyle Width="33.3%"/>
<ItemTemplate>
<asp:Label ID="lblAttributeNameID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container.
<span style="color:#58595B;font-
<div style="height:100px;overfl
<asp:DataList ID="dlAttributeValues" runat="server">
<ItemTemplate>
<asp:Label ID="lblAttrNameID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container.
<asp:Label ID="lblAttributeValueID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container.
<asp:checkbox ID="chkValue" runat="server" Text='<%# DataBinder.Eval(Container.
</ItemTemplate>
</asp:DataList>
</div>
</ItemTemplate>
</asp:DataList>
</div>
Try this mate ..
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="dlAttributes" runat="server" DataKeyField="ID" RepeatDirection="Horizontal" RepeatColumns="3" Width="100%">
<ItemStyle Width="33.3%"/>
<ItemTemplate>
<asp:HiddenField ID="parentRowIndex" runat="Server" value='<%# Container.ItemIndex + 1 %>' />
<asp:Label ID="lblAttributeNameID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container.DataItem, "ID")%>'></asp:Label>
<span style="color:#58595B;font-size:14px;font-weight:bold;"><%# DataBinder.Eval(Container.DataItem, "name")%></span>
<div style="height:100px;overflow:auto; border: 1px solid #CACACA;margin:10px 10px 10px 0px;padding:10px;">
<asp:DataList ID="dlAttributeValues" runat="server" DataSource='<%# getTable() %>' OnItemCommand="DlChild_ItemCommand">
<ItemTemplate>
<asp:Label ID="lblAttributeValueID" runat="server" Visible = "true"
Text='<%# DataBinder.Eval(Container.DataItem, "salary")%>'></asp:Label>
<asp:checkbox ID="chkValue" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"degree")%>'
AutoPostBack="true" OnCheckedChanged="GetLabel" />
</ItemTemplate>
</asp:DataList>
</div>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
Imports System.Data
Partial Class dataListCheckBoxFireEvent
Inherits System.Web.UI.Page
Dim ds As New DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ds.ReadXml(Server.MapPath("~/xmlfile2.xml"))
If Not IsPostBack Then
dlAttributes.DataSource = ds
dlAttributes.DataBind()
End If
End Sub
Protected Sub GetLabel(ByVal sender As Object, ByVal e As System.EventArgs)
Dim chk As CheckBox = DirectCast(sender, CheckBox)
Dim parentIndex As Integer = getParentIndex(chk.ClientID)
Dim dsAttValue As DataList = DirectCast(dlAttributes.Items(parentIndex).FindControl("dlAttributeValues"), DataList) 'This finds respect child datalist
If chk.Checked Then
For Each Items1 In dsAttValue.Items
Dim childCheckBox As CheckBox = Items1.FindControl("chkValue") 'Credits to CodeCruiser
childCheckBox.Enabled = False
Next
End If
End Sub
Protected Function getTable() As DataTable
Dim dsChild As New DataSet
dsChild.ReadXml(Server.MapPath("~/xmlfile2.xml"))
Return dsChild.Tables(0)
End Function
Function getParentIndex(ByVal id As String) As String
Dim str As String
Dim i As Integer
str = id
Dim chkNext As Integer = 0
Dim parentIndex As String = ""
For i = 1 To Len(str)
If IsNumeric(Mid(str, i, 1)) Then
parentIndex += Mid(str, i, 1)
chkNext = i
End If
If parentIndex <> "" And chkNext <> i Then
Exit For
End If
Next i
Return parentIndex
End Function
End Class
XMLFile2.xml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this is the proper nested datalist , .
<asp:DataList ID="dlAttributes" runat="server" DataKeyField="ID" RepeatDirection="Horizontal" RepeatColumns="3" Width="100%">
<ItemStyle Width="33.3%"/>
<ItemTemplate>
<asp:Label ID="lblAttributeNameID" runat="server" Visible = "false" Text='<%# DataBinder.Eval(Container.DataItem, "ID")%>'></asp:Label>
<span style="color:#58595B;font-size:14px;font-weight:bold;"><%# DataBinder.Eval(Container.DataItem, "name")%></span>
<div style="height:100px;overflow:auto; border: 1px solid #CACACA;margin:10px 10px 10px 0px;padding:10px;">
<asp:DataList ID="dlAttributeValues" runat="server" DataSource='<%# getTable() %>' >
<ItemTemplate>
<asp:Label ID="lblAttributeValueID" runat="server" Visible = "true"
Text='<%# DataBinder.Eval(Container.DataItem, "salary")%>'></asp:Label>
<asp:checkbox ID="chkValue" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"degree")%>'
AutoPostBack="true" OnCheckedChanged="GetLabel" />
</ItemTemplate>
</asp:DataList>
</div>
</ItemTemplate>
</asp:DataList>
Open in new window