Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 05, 2008 06:44 AM by kannanmca
Member
1 Points
15 Posts
Jul 01, 2008 07:58 AM|LINK
I have e.g 3 items in my ListBox
ITEM 1 ITEM 2 ITEM 3
Lets assume ITEM 2 and ITEM 3 is get from data source and I set its DataTextField as "Name" and DataValueField As "ID"
ITEM1 is insert by the following command ListBox1.Items.Insert(0,"ITEM 1")
How do I assign e.g a value "item1value" to ITEM 1 and not changing its text. Means it show ITEM 1 ITEM 2 ITEM 3
But when I call ListBox1.SelectedValue (assume at this moment i select ITEM 1) , it will return me item1value instead of ITEM 1
Thanks, Baoky
listbox selectedvalue assign
All-Star
25882 Points
3993 Posts
MVP
Jul 01, 2008 08:21 AM|LINK
use this
ListBox1.Items.Insert(0,new ListItem("ITEM 1", "Value"))
Star
7928 Points
1506 Posts
Jul 01, 2008 08:22 AM|LINK
You have to create a new ListItem and use it instead of just inserting a string
lstTest.Items.Insert(0, new ListItem("ITEM 1", "0"));
8607 Points
1841 Posts
Jul 01, 2008 08:25 AM|LINK
try this...
ListItem
ddlist.Items.Insert(0, li);
425 Points
90 Posts
Jul 01, 2008 08:36 AM|LINK
if you using dataset means why you are inserting values into Listbox . just u can bind data into datalist using following method
ListBox1 .DataSource = Datasetname.Tables[tablename ];
ListBox1.DataBind();
when you selelcting listbox why you are getting item1 only behalf of Id means .. you have not set the value for listitem.
so u can use following code for inserting value
Dim NewItem As ListItem NewItem = New ListItem("text","value") ListBox.Items.Add(NewItem) or ListBox.Items.Add(New ListItem("text","value")) ListBox.Items.Insert(index, New ListItem("text","value")) ListBox.Items.RemoveAt(index) ListBox.Items.Clear()
50 Points
25 Posts
Sep 05, 2008 06:44 AM|LINK
hi,
im entry level prg..
my listbox contain several datas
for example..
Listbox contain
1
2
3
,
22 datas..
now im add new item in listbox..
vertical scroll bar automatically move to "newly added item"...
Plz give me a solution for me..
Thx in advance...
baokychen
Member
1 Points
15 Posts
How to Assign Value to ListBox.Items.Insert
Jul 01, 2008 07:58 AM|LINK
I have e.g 3 items in my ListBox
ITEM 1
ITEM 2
ITEM 3
Lets assume ITEM 2 and ITEM 3 is get from data source and I set its DataTextField as "Name" and DataValueField As "ID"
ITEM1 is insert by the following command ListBox1.Items.Insert(0,"ITEM 1")
How do I assign e.g a value "item1value" to ITEM 1 and not changing its text.
Means it show
ITEM 1
ITEM 2
ITEM 3
But when I call ListBox1.SelectedValue (assume at this moment i select ITEM 1) , it will return me item1value instead of ITEM 1
Thanks,
Baoky
listbox selectedvalue assign
vik20000in
All-Star
25882 Points
3993 Posts
MVP
Re: How to Assign Value to ListBox.Items.Insert
Jul 01, 2008 08:21 AM|LINK
use this
ListBox1.Items.Insert(0,new ListItem("ITEM 1", "Value"))
www.vikramlakhotia.com
Please mark the answer if it helped you
anzer
Star
7928 Points
1506 Posts
Re: How to Assign Value to ListBox.Items.Insert
Jul 01, 2008 08:22 AM|LINK
You have to create a new ListItem and use it instead of just inserting a string
lstTest.Items.Insert(0, new ListItem("ITEM 1", "0"));
ClientSideAsp.Net | Blog
christiandev
Star
8607 Points
1841 Posts
Re: How to Assign Value to ListBox.Items.Insert
Jul 01, 2008 08:25 AM|LINK
try this...
ListItem
li = new ListItem();li.Text = "Item 1";
li.Value = "Item 1 Value";
ddlist.Items.Insert(0, li);
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)
gnanam02
Member
425 Points
90 Posts
Re: How to Assign Value to ListBox.Items.Insert
Jul 01, 2008 08:36 AM|LINK
if you using dataset means why you are inserting values into Listbox . just u can bind data into datalist using following method
ListBox1 .DataSource = Datasetname.Tables[tablename ];
ListBox1.DataValueField = "ID";ListBox1.DataTextField = "items";ListBox1.DataBind();
when you selelcting listbox why you are getting item1 only behalf of Id means .. you have not set the value for listitem.
so u can use following code for inserting value
Dim NewItem As ListItem
NewItem = New ListItem("text","value")
ListBox.Items.Add(NewItem)
or
ListBox.Items.Add(New ListItem("text","value"))
ListBox.Items.Insert(index, New ListItem("text","value"))
ListBox.Items.RemoveAt(index)
ListBox.Items.Clear()
Gnana Prakash S
Software Engineer
Coimbatore
http://www.sgnanaprakash.com
kannanmca
Member
50 Points
25 Posts
How to Auto-select and show Last Item In Listbox
Sep 05, 2008 06:44 AM|LINK
hi,
im entry level prg..
my listbox contain several datas
for example..
Listbox contain
1
2
3
,
,
22 datas..
now im add new item in listbox..
vertical scroll bar automatically move to "newly added item"...
Plz give me a solution for me..
Thx in advance...