Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
==>how to bind listbox items from database...

==> 2 listbox for different languages.. (like matromony..and job related websites have..)

==>first listbox bind from database (languages table)

==> second listbox is blank

==>select multiple languages from first listbox and store into second listbox

==> which languages are selected in second listbox...those languages are removed from first listbox
.

==> i know the simple coding of two listbox like add, add_all, move, move_all
but dont know how to access with database...how to store in database and bind from database...
and when bind from database...that time which languages are in second listbox....they will not have in firstlistbox...
.m sorry for my dangerous explainantion to you..
give me simple coding..
Posted

Fill the List Box

DataTable UserInfo = con.GetData("select distinct UserName,UserID from tbl_UserDetails order by UserName");
if (UserInfo.Rows.Count > 0)
{
lstAvaliableUserPool.DataSource = UserInfo;
lstAvaliableUserPool.DataTextField = "UserName";
//lstAvaliableUserPool.DataValueField = "UserID";
lstAvaliableUserPool.DataBind();
}



protected void btnSelectUser_Click(object sender, EventArgs e)
{

if (lstAvaliableUserPool.SelectedIndex != -1)
{
lstSelectedUserPool.Items.Add(lstAvaliableUserPool.SelectedItem.Text);
lstAvaliableUserPool.Items.RemoveAt(lstAvaliableUserPool.SelectedIndex);
}
}

protected void btnDeSelectUser_Click(object sender, EventArgs e)
{

if (lstSelectedUserPool.SelectedValue != "")
{
lstAvaliableUserPool.Items.Add(lstSelectedUserPool.SelectedValue);
lstSelectedUserPool.Items.RemoveAt(lstSelectedUserPool.SelectedIndex);
}
}

protected void btnSelectAllUsers_Click(object sender, EventArgs e)
{

for (int i = 0; i < lstAvaliableUserPool.Items.Count; i++)
{
lstSelectedUserPool.Items.Add(lstAvaliableUserPool.Items[i].Text);
}
lstAvaliableUserPool.Items.Clear();
}

protected void btndeSelectAllUsers_Click(object sender, EventArgs e)
{

for (int i = 0; i < lstSelectedUserPool.Items.Count; i++)
{
lstAvaliableUserPool.Items.Add(lstSelectedUserPool.Items[i].Text);
}
lstSelectedUserPool.Items.Clear();
}
 
Share this answer
 
v2
Comments
Manish Dalwadi 24-Jan-14 5:12am    
thanks
subbuksr123 24-Jan-14 5:19am    
welcome
:)
<table >
<tr>
<td>
&nbsp;
</td>
<td>
<asp:ListBox ID="lstAvaliableUserPool" runat="server" Font-Names="Arial"
Height="150px" Width="170px"></asp:ListBox>
</td>
<td align="center" valign="middle">
<center>
<table>
<tr>
<td align="center" valign="middle" width="35">
<asp:Button ID="btnSelectUser" runat="server" Font-Bold="True" Font-Names="Arial"
Font-Size="8pt" Height="20px" OnClick="btnSelectUser_Click" Text="&gt;" Width="30px" />
</td>
</tr>
<tr>
<td align="center" valign="middle" width="35">
<asp:Button ID="btnDeSelectUser" runat="server" Font-Bold="True" Font-Names="Arial"
Font-Size="8pt" Height="20px" OnClick="btnDeSelectUser_Click" Text="&lt;" Width="30px" />
</td>
</tr>
<tr>
<td align="center" valign="middle" width="35">
<asp:Button ID="btnSelectAllUsers" runat="server" Font-Bold="True" Font-Names="Arial"
Font-Size="8pt" Height="20px" OnClick="btnSelectAllUsers_Click" Text="&gt;&gt;"
Width="30px" />
</td>
</tr>
<tr>
<td align="center" valign="middle" width="35">
<asp:Button ID="btndeSelectAllUsers" runat="server" Font-Bold="True" Font-Names="Arial"
Font-Size="8pt" Height="20px" OnClick="btndeSelectAllUsers_Click" Text="&lt;&lt;"
Width="30px" />
</td>
</tr>
</table>
</center>
</td>
<td>
<asp:ListBox ID="lstSelectedUserPool" runat="server" Font-Names="Arial"
Height="150px" Width="170px"></asp:ListBox>
</td>
</tr>
</table>
 
Share this answer
 
v3
Take one data table which contains fields for first list box.

Add one more column for holding flag for list box 1 & list box 2 items

Bind first list box.

After selecting records from first list box,update data table flag values according to items for list box 2 (Selected from first list box)

Before bind list box 2, try to sort data table values according to first & second list box & then bind it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900