ListPicker

Vipul
Posted by in ASP.NET category on for Beginner level | Views : 6641 red flag

There is no more difference in windows and web listbox it is so simple to implement in web.


 Download source code for ListPicker

 
 
ListPicker

This ListPicker is easily available in windows application.But i have create it in web.


1.Suppose you have one web page name is Default or whatever,I take as Default.

<style type="text/css">

.listPicker

{

border:solid 1px black;

padding:5px;

width:380px;

background-color:silver;

}

.listPicker select

{

width:100%;

}

</style>

2.Write Following Code in Body part

<form id="form1" runat="server">

<div class="listPicker">

<div style="float:left;width:40%">

<asp:ListBox

id="lstAllMovies"

DataSourceID="srcMovies"

DataTextField="Title"

DataValueField="Id"

Runat="server" />

</div>

<div style="float:left;width:20%;text-align:center">

<asp:Button

id="btnAdd"

Text="--&gt;"

ToolTip="Add List Item"

Runat="server" OnClick="btnAdd_Click" />

<br />

<asp:Button

id="btnRemove"

Text="&lt;--"

ToolTip="Remove List Item"

Runat="server" OnClick="btnRemove_Click" />

</div>

<div style="float:left;width:40%">

<asp:ListBox

id="lstFavoriteMovies"

Runat="server" />

</div>

<br style="clear:both" />

</div>

<p>

<asp:Button

id="btnSubmit"

Text="Submit Form"

Runat="server" OnClick="btnSubmit_Click" />

</p>

<hr />

<asp:Label

id="lblResults"

EnableViewState="false"

Runat="server" />

<asp:SqlDataSource

id="srcMovies"

SelectCommand="SELECT Id, Title FROM Movies"

ConnectionString="Write Your connection String"

Runat="server" />

</form>

3.Write Following code in Defaut.aspx.cs

protected void btnSubmit_Click(object sender, EventArgs e)

{

foreach (ListItem item in lstFavoriteMovies.Items)

lblResults.Text += "<li>" + item.Text;

}

protected void btnAdd_Click(object sender, EventArgs e)

{

ListItem item = lstAllMovies.SelectedItem;

if (item != null)

{

lstAllMovies.Items.Remove(item);

lstFavoriteMovies.ClearSelection();

lstFavoriteMovies.Items.Add(item);

}

}

protected void btnRemove_Click(object sender, EventArgs e)

{

ListItem item = lstFavoriteMovies.SelectedItem;

if (item != null)

{

lstFavoriteMovies.Items.Remove(item);

lstAllMovies.ClearSelection();

lstAllMovies.Items.Add(item);

}

}

4.For better understanding download source.

Page copy protected against web site content infringement by Copyscape

About the Author

Vipul
Full Name: vipul vk
Member Level: Starter
Member Status: Member
Member Since: 4/15/2009 9:08:15 PM
Country:

http://www.dotnetfunda.com
Working as a software developer

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)