Hi,
i am using select2 jquery in asp.net. my problem is i have some item catagory and those item catagories has many items respectively. when i binded that listbox, items are coming properly. but i want these items with items catagory. e.g.
item_cat1
item_1
item_2
item_cat2
item_3
please help to find out items with item catagories.. i need items as a time zone example in
My aspx page code is:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Listbox.aspx.cs" Inherits="Listbox" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script>
$(document).ready(function () {
$("#lstItemGroup").select2({ placeholder: 'Find and Select Country' });
});
function Page_Load() {
$(document).ready(function () {
$("#lstItemGroup").select2({ placeholder: 'Find and Select Country' });
});
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<table>
<tr>
<td>
<div id="e2">
<asp:ListBox ID="lstItemGroup" Style="width: 300px" runat="server" SelectionMode="Multiple"
ClientIDMode="Static"></asp:ListBox>
</div>
</td>
<td>
<asp:Label ID="lblItemsID" runat="server"></asp:Label>
</td>
<td style="background-color: Gray;">
<asp:Label ID="lblItemName" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
<div>
<asp:Button ID="btn" runat="server" Text="Button" OnClick="btn_Click1" />
</div>
</asp:Content>
my .cs page is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
bindCountry();
}
public void bindCountry()
{
//SqlConnection con = new SqlConnection("Data Source=XBSDNETDB;Persist Security Info=False;" +
// "Initial Catalog=P50_T;User Id=P50_T;Password=P50_T;") ;
//SqlCommand cmd = con.CreateCommand();
DataTable dtCountry = null;
DataSet dsCountry = null;
string strItemGroupId = " select b.item_group_id, b.item_group_name,a.item_name,a.item_id from xbs_mast_item a, xbs_mast_item_group b ";
strItemGroupId += " where a.valid_flg='Y' and b.valid_flg='Y' and a.item_group_id=b.item_group_id order by item_group_name";
dsCountry = XBSDAL.ExecuteDataset(CommandType.Text, strItemGroupId);
dtCountry = dsCountry.Tables[0];
lstItemGroup.DataSource = dtCountry;
lstItemGroup.DataValueField = "item_id";
lstItemGroup.DataTextField = "item_name";
lstItemGroup.DataBind();
lstItemGroup.Attributes.Add("multiple", "true");
//Books.Multiple = true;
}
protected void btn_Click1(object sender, EventArgs e)
{
if (lstItemGroup.SelectedItem != null)
{
lblItemsID.Text = "";
lblItemName.Text = "";
foreach (ListItem li in lstItemGroup.Items)
{
if (li.Selected == true)
{
lblItemsID.Text += li.Value + ",";
lblItemName.Text += li.ToString() + ",";
}
}
}
}