Hi Bhavesh23,
Please refer below sample.
HTML
<asp:DropDownList runat="server" ID="dropblockselection" AutoPostBack="true"
OnSelectedIndexChanged="ddlDetails_SelectedIndexChanged">
<asp:ListItem Text="Select" />
<asp:ListItem Text="1 To 7" Value="1" />
<asp:ListItem Text="8 To 14" Value="2" />
<asp:ListItem Text="P1/P2" Value="3" />
<asp:ListItem Text="Meetingroom" Value="4" />
</asp:DropDownList>
<hr />
<asp:CheckBoxList runat="server" ID="chkblockselection" RepeatColumns="4"
RepeatDirection="Horizontal" Height="157px" Width="289px" CssClass="auto-style1"
BorderStyle="Solid" Font-Bold="True" AutoPostBack="True" Enabled="False">
<asp:ListItem Text="0" Value="0" />
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
<asp:ListItem Text="4" Value="4" />
<asp:ListItem Text="5" Value="5" />
<asp:ListItem Text="6" Value="6" />
<asp:ListItem Text="7" Value="7" />
<asp:ListItem Text="8" Value="8" />
<asp:ListItem Text="9" Value="9" />
<asp:ListItem Text="10" Value="10" />
<asp:ListItem Text="11" Value="11" />
<asp:ListItem Text="12" Value="12" />
<asp:ListItem Text="13" Value="13" />
<asp:ListItem Text="14" Value="14" />
<asp:ListItem Text="15" Value="15" />
<asp:ListItem Text="16" Value="16" />
</asp:CheckBoxList>
Code
C#
protected void ddlDetails_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem item in chkblockselection.Items)
{
item.Selected =false;
}
if (dropblockselection.SelectedItem.Text == "1 To 7")
{
chkblockselection.Enabled = true;
int start = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(new string[] { "to" }, StringSplitOptions.None)[0].Trim()) - 1;
int end = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(new string[] { "to" }, StringSplitOptions.None)[1].Trim());
foreach (ListItem item in chkblockselection.Items)
{
item.Enabled = Convert.ToInt16(item.Value) >= start && Convert.ToInt16(item.Value) < end ? true : false;
}
}
if (dropblockselection.SelectedItem.Text == "8 To 14")
{
chkblockselection.Enabled = true;
int start = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(new string[] { "to" }, StringSplitOptions.None)[0].Trim()) - 1;
int end = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(new string[] { "to" }, StringSplitOptions.None)[1].Trim());
foreach (ListItem item in chkblockselection.Items)
{
item.Enabled = Convert.ToInt16(item.Value) >= start && Convert.ToInt16(item.Value) < end ? true : false;
}
}
if (dropblockselection.SelectedItem.Text == "P1/P2")
{
chkblockselection.Enabled = true;
int start = 14;
int end = 15;
foreach (ListItem item in chkblockselection.Items)
{
item.Enabled = Convert.ToInt16(item.Value) >= start && Convert.ToInt16(item.Value) <= end ? true : false;
}
chkblockselection.Items.FindByValue("16").Enabled = false;
}
if (dropblockselection.SelectedItem.Text == "Meetingroom")
{
chkblockselection.Enabled = true;
int start = 0;
int end = 16;
foreach (ListItem item in chkblockselection.Items)
{
item.Enabled = Convert.ToInt16(item.Value) >= start && Convert.ToInt16(item.Value) < end ? false : true;
}
chkblockselection.Items.FindByValue("16").Enabled = true;
}
}
VB.Net
Protected Sub ddlDetails_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
For Each item As ListItem In chkblockselection.Items
item.Selected = False
Next
If dropblockselection.SelectedItem.Text = "1 To 7" Then
chkblockselection.Enabled = True
Dim start As Integer = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(New String() {"to"}, StringSplitOptions.None)(0).Trim()) - 1
Dim [end] As Integer = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(New String() {"to"}, StringSplitOptions.None)(1).Trim())
For Each item As ListItem In chkblockselection.Items
item.Enabled = If(Convert.ToInt16(item.Value) >= start AndAlso Convert.ToInt16(item.Value) < [end], True, False)
Next
End If
If dropblockselection.SelectedItem.Text = "8 To 14" Then
chkblockselection.Enabled = True
Dim start As Integer = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(New String() {"to"}, StringSplitOptions.None)(0).Trim()) - 1
Dim [end] As Integer = Convert.ToInt16(dropblockselection.SelectedItem.Text.ToLower().Split(New String() {"to"}, StringSplitOptions.None)(1).Trim())
For Each item As ListItem In chkblockselection.Items
item.Enabled = If(Convert.ToInt16(item.Value) >= start AndAlso Convert.ToInt16(item.Value) < [end], True, False)
Next
End If
If dropblockselection.SelectedItem.Text = "P1/P2" Then
chkblockselection.Enabled = True
Dim start As Integer = 14
Dim [end] As Integer = 15
For Each item As ListItem In chkblockselection.Items
item.Enabled = If(Convert.ToInt16(item.Value) >= start AndAlso Convert.ToInt16(item.Value) <= [end], True, False)
Next
chkblockselection.Items.FindByValue("16").Enabled = False
End If
If dropblockselection.SelectedItem.Text = "Meetingroom" Then
chkblockselection.Enabled = True
Dim start As Integer = 0
Dim [end] As Integer = 16
For Each item As ListItem In chkblockselection.Items
item.Enabled = If(Convert.ToInt16(item.Value) >= start AndAlso Convert.ToInt16(item.Value) < [end], False, True)
Next
chkblockselection.Items.FindByValue("16").Enabled = True
End If
End Sub
Screenshot