Hi Waghmare,
Refer below code.
HTML
<div align="center">
<asp:ListBox ID="lstFruits" runat="server" SelectionMode="Multiple">
<asp:ListItem Text="Mango" Value="1" />
<asp:ListItem Text="Apple" Value="2" />
<asp:ListItem Text="Banana" Value="3" />
<asp:ListItem Text="Guava" Value="4" />
<asp:ListItem Text="Orange" Value="5" />
</asp:ListBox>
<asp:Button Text="Disable Select All" runat="server" OnClick="OnDisable" />
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css" />
<script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('[id*=lstFruits]').multiselect({
includeSelectAllOption: true
});
});
function DisableSelectAll() {
$('input[value="multiselect-all"]').attr("disabled", true);
}
</script>
Code
C#
protected void OnDisable(object sender, EventArgs e)
{
int selectedCount = 0;
foreach (ListItem item in lstFruits.Items)
{
item.Selected = true;
item.Attributes.Add("disabled", "disabled");
selectedCount++;
}
if (lstFruits.Items.Count == selectedCount)
{
string script = "window.onload = function() { DisableSelectAll(); };";
ClientScript.RegisterStartupScript(this.GetType(), "DisableSelectAll", script, true);
}
}
VB.Net
Protected Sub OnDisable(ByVal sender As Object, ByVal e As EventArgs)
Dim selectedCount As Integer = 0
For Each item As ListItem In lstFruits.Items
item.Selected = True
item.Attributes.Add("disabled", "disabled")
selectedCount += 1
Next
If lstFruits.Items.Count = selectedCount Then
Dim script As String = "window.onload = function() { DisableSelectAll(); };"
ClientScript.RegisterStartupScript(Me.GetType(), "DisableSelectAll", script, True)
End If
End Sub
Screenshot