ListBox and ItemData

M

Michael Debus

Hi,
i use the ListBox Control in a ASP.NET Appl. I fill the ListBox with serval
items using ListBox.Item.Add.
Now i will give each item a unique identifier as a long value to identify
the item, when it is selected by the user. I search for a method like
CListBox.SetItemData and CListBox.GetItemData in MFC programming.
Is there any corresponding function in ASP.NET ?
thanks for your help.
Michael Debus
 
T

Teemu Keiski

Hi,

you could add the value when you'd use overload if Items.Add method which
takes a ListItem instance.

ListBox1.Items.Add(new ListItem("text1","value1"));
ListBox1.Items.Add(new ListItem("text1","value1"));

Does this help?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

Hi,
i use the ListBox Control in a ASP.NET Appl. I fill the ListBox with serval
items using ListBox.Item.Add.
Now i will give each item a unique identifier as a long value to identify
the item, when it is selected by the user. I search for a method like
CListBox.SetItemData and CListBox.GetItemData in MFC programming.
Is there any corresponding function in ASP.NET ?
thanks for your help.
Michael Debus
 
R

rwg

Michael:

In VS, I created a project, added a WebForm DropDownList called ddBox and a label called lblSelected and coded Page_Load like this:

private void Page_Load(object sender, System.EventArgs e)
{
if ( IsPostBack )
{
lblSelected.Text = "Index=" + ddBox.SelectedIndex.ToString()
+ ", Item=" + ddBox.SelectedItem.ToString()
+ ", Value=" + ddBox.SelectedValue.ToString() ;
}
else
{
ddBox.Items.Add( new ListItem( "Apples are good", "1" ) );
ddBox.Items.Add( new ListItem( "Bakers bake applie", "2" ) );
ddBox.Items.Add( new ListItem( "Charly eats baked goods", "3" ) );
}
}



-rwg
This is what I think, not necessarily what is accurate!

--------------------
| From: "Michael Debus" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| Subject: ListBox and ItemData
| Date: Sun, 11 Apr 2004 19:10:15 +0200
|
| Hi,
| i use the ListBox Control in a ASP.NET Appl. I fill the ListBox with serval
| items using ListBox.Item.Add.
| Now i will give each item a unique identifier as a long value to identify
| the item, when it is selected by the user. I search for a method like
| CListBox.SetItemData and CListBox.GetItemData in MFC programming.
| Is there any corresponding function in ASP.NET ?
| thanks for your help.
| Michael Debus
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ListBox 1
Listbox bug(?) 1
listbox 5
Listbox items index 0
Can preselect databound listbox items 0
listbox 0
Composite Control ListBox SelectedIndexChanged event not firing 0
Formatted Listbox? 1

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top