Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 27, 2012 04:59 PM by Nguyen Van Quyen
0 Points
5 Posts
Mar 27, 2012 04:27 PM|LINK
Hello every body !
I have a Question, I try Code but this not work !, I don't know why ?
detail question
I had,
public DataTable query(string strquery,SqlConnection con) { DataTable tbl = new DataTable(); SqlDataAdapter dapter = new SqlDataAdapter(strquery, con); dapter.Fill(tbl); return tbl; }
and i using string query "Select username from user order by username", to add item into ListUser, this add succeeded !
now, I want, when i select item index other in all items of ListUser then ListUser will Display text of Item selected
ex have 5 items and when ...
item 1 : text Jim Smith -> ListUser.Text = Jim Smith
item 2 : text Micheal -> ListUser.Text = Micheal
How do I ... what I want ?
plz help me !!! tks
Star
9337 Points
1447 Posts
Mar 27, 2012 04:42 PM|LINK
To get selected Item text:
ListUser.SelectedItem.Text //this would give you "Jim Smith"
To get selected Item value:
ListUser.SelectedItem.Value //this would give you "Jim Smith" because you have not set ListUser.DataValueField
If you bind ListUser like this:
ListUser.DataSource =query("Select IDuser, username from user order by username", connection);
ListUser.DataTextField = "username";
ListUser.DataValueField = "IDuser";
ListUser.DataBind();
-----
ListUser.SelectedItem.Value //this would give you id of "Jim Smith" because now ListUser.DataValueField is set to IDuser
Make sure you bind ListUser inside if(!IsPostBack){} on Page_Load.
Thanks
Mar 27, 2012 04:59 PM|LINK
tks me_ritz , so much...
this is great and working same what i want
i will continues stydy Your Code ! tks
Nguyen Van Q...
0 Points
5 Posts
[Help-Support] Get Values Item selected from dropdownlist
Mar 27, 2012 04:27 PM|LINK
Hello every body !
I have a Question, I try Code but this not work !
, I don't know why ?
detail question
I had,
and i using string query "Select username from user order by username", to add item into ListUser, this add succeeded !
now, I want, when i select item index other in all items of ListUser then ListUser will Display text of Item selected
ex have 5 items and when ...
item 1 : text Jim Smith -> ListUser.Text = Jim Smith
item 2 : text Micheal -> ListUser.Text = Micheal
How do I ... what I want ?
plz help me !!! tks
me_ritz
Star
9337 Points
1447 Posts
Re: [Help-Support] Get Values Item selected from dropdownlist
Mar 27, 2012 04:42 PM|LINK
To get selected Item text:
ListUser.SelectedItem.Text //this would give you "Jim Smith"
To get selected Item value:
ListUser.SelectedItem.Value //this would give you "Jim Smith" because you have not set ListUser.DataValueField
If you bind ListUser like this:
ListUser.DataSource =query("Select IDuser, username from user order by username", connection);
ListUser.DataTextField = "username";
ListUser.DataValueField = "IDuser";
ListUser.DataBind();
-----
ListUser.SelectedItem.Text //this would give you "Jim Smith"
ListUser.SelectedItem.Value //this would give you id of "Jim Smith" because now ListUser.DataValueField is set to IDuser
Make sure you bind ListUser inside if(!IsPostBack){} on Page_Load.
Thanks
Nguyen Van Q...
0 Points
5 Posts
Re: [Help-Support] Get Values Item selected from dropdownlist
Mar 27, 2012 04:59 PM|LINK
tks me_ritz , so much...
this is great and working same what i want
i will continues stydy Your Code ! tks