Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 06, 2012 02:03 AM by mustafaiqbal
Member
47 Points
57 Posts
Aug 10, 2011 01:23 PM|LINK
Hi, i really need your help..
Can u help me to get selected value from listview? So that i can read one record..
thanks before..
Contributor
4834 Points
893 Posts
Aug 10, 2011 01:32 PM|LINK
Say that you fire the SelectedIndexChanged event handler;
Just add this code to find say Label control within selected item:
Dim MyTitle As Label = CType(ListView1.Items(ListView1.SelectedIndex).FindControl("MyLabelControl"), Label) Label MyTitle = (Label)ListView1.Items(ListView1.SelectedIndex).FindControl("MyLabelControl");
All-Star
53942 Points
8147 Posts
Aug 10, 2011 01:34 PM|LINK
You can get the selected Item using SelectedIndex
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e) { ListViewItem selectedItem = ListView1.Items[ListView1.SelectedIndex]; }
Add OnselectedIndexChanged="ListView1_SelectedIndexChanged" for the listview in the page markup.
Aug 10, 2011 02:59 PM|LINK
Kulrom, thx for your replay..
Hmm... Looks little bit complicated to understand.. I just want to get selected id from listview.
i usually use gridview. In gridview, i can get selected value with :
string id = GridView_Main.SelectedValue.ToString();
and add :
OnSelectedIndexChanged="GridView_Main_SelectedIndexChanged"
but i dont know how to get that value in listview..
Aug 10, 2011 03:06 PM|LINK
sansan, thx for your replay..
can't i change "ListViewItem" with data type like string or int??
ex :
string id = ........ ;
coz i will use that id to filter my table like this:
var notification = db.DMSDataContext.Notifikasis.Where(p => p.IdNotifikasi.Equals(id)).Single();
Aug 10, 2011 04:29 PM|LINK
Please specify the datakeynames of the listview to ID and you can retrieve the value as shown below
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e) { string id = ListView1.SelectedDataKey.Value.ToString(); }
4 Points
2 Posts
Nov 06, 2012 02:03 AM|LINK
Hello Sansan,
If I have many Fileds (With an Image), I can apply that or not? Or if user click on Image, please tell me how to get value?
kieky
Member
47 Points
57 Posts
How to get selected value from LIstView
Aug 10, 2011 01:23 PM|LINK
Hi, i really need your help..
Can u help me to get selected value from listview? So that i can read one record..
thanks before..
Kulrom
Contributor
4834 Points
893 Posts
Re: How to get selected value from LIstView
Aug 10, 2011 01:32 PM|LINK
Say that you fire the SelectedIndexChanged event handler;
Just add this code to find say Label control within selected item:
Dim MyTitle As Label = CType(ListView1.Items(ListView1.SelectedIndex).FindControl("MyLabelControl"), Label) Label MyTitle = (Label)ListView1.Items(ListView1.SelectedIndex).FindControl("MyLabelControl");My Blog: ASP.NET Stuff
sansan
All-Star
53942 Points
8147 Posts
Re: How to get selected value from LIstView
Aug 10, 2011 01:34 PM|LINK
You can get the selected Item using SelectedIndex
Add OnselectedIndexChanged="ListView1_SelectedIndexChanged" for the listview in the page markup.
kieky
Member
47 Points
57 Posts
Re: How to get selected value from LIstView
Aug 10, 2011 02:59 PM|LINK
Kulrom, thx for your replay..
Hmm... Looks little bit complicated to understand.. I just want to get selected id from listview.
i usually use gridview. In gridview, i can get selected value with :
and add :
but i dont know how to get that value in listview..
kieky
Member
47 Points
57 Posts
Re: How to get selected value from LIstView
Aug 10, 2011 03:06 PM|LINK
sansan, thx for your replay..
can't i change "ListViewItem" with data type like string or int??
ex :
coz i will use that id to filter my table like this:
sansan
All-Star
53942 Points
8147 Posts
Re: How to get selected value from LIstView
Aug 10, 2011 04:29 PM|LINK
Please specify the datakeynames of the listview to ID and you can retrieve the value as shown below
mustafaiqbal
Member
4 Points
2 Posts
Re: How to get selected value from LIstView
Nov 06, 2012 02:03 AM|LINK
Hello Sansan,
If I have many Fileds (With an Image), I can apply that or not? Or if user click on Image, please tell me how to get value?