After populating the Cars in ListBox. You need to select the data base on Company Name from Selected Table.
This is just a reference code.
Suppose you have selected the Maruti brand and from Maruti band Cars you need to show the Selected ones. Please refer this code.
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
rel="stylesheet" type="text/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*=lbCars]').multiselect({
includeSelectAllOption: true
});
});
</script>
<asp:ListBox ID="lbCars" runat="server" SelectionMode="Multiple">
<asp:ListItem Text="ALTO" Value="1" />
<asp:ListItem Text="ZEN" Value="2" />
<asp:ListItem Text="CIAZ" Value="3" />
<asp:ListItem Text="ESTEEM" Value="2" />
</asp:ListBox>
Add this code to Populate the Selected Cars of perticular company.
Here i have shown it in the Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//Get it form database.
string selectedCars = "2,3,4";
string[] selectedCarsArray = selectedCars.Split(',');
foreach (string s in selectedCarsArray)
{
foreach (ListItem item in lbCars.Items)
{
if (s == item.Value)
{
item.Selected = true;
}
}
}
}
VB.net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim selectedCars As String = "2,3,4"
Dim selectedCarsArray As String() = selectedCars.Split(","c)
For Each s As String In selectedCarsArray
For Each item As ListItem In lbCars.Items
If s = item.Value Then
item.Selected = True
End If
Next
Next
End Sub
Screenshot