Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a Listview named "listview1". I am displaying students name in the list view.

I got collection of students Id and name in a data table.

// appending the students name in the listview
C#
foreach (DataRow dr in dtStudentInfo.Rows)
             { 
                Item = listView1.Items.Add(dr["strName"].ToString());
                Item.Tag = dr["nId"].ToString();
             }    

question : How can i get name of the student if i know the student Id?
Eg: For the student Id 5 i want to know the name of the student.
Here i can do this by getting whole item collection inside a for loop and
i can compare the tag. But i want a direct method where i can specify the tag as 5 and get
student name for the respective tag?
Posted
Updated 13-Aug-12 20:37pm
v2
Comments
prashant patil 4987 14-Aug-12 2:47am    
hey cockyrabbit779,
can you lpease tell me which version of .net Framework you use..??
code4Better 14-Aug-12 3:10am    
Dotnet 2.0

Hi,

You can search for particular text using LINQ. you need little knowledge to do that.

Please check this[^] discussion.

You will find solution.

Thanks
-Amit Gajjar
 
Share this answer
 
Comments
code4Better 14-Aug-12 6:21am    
Thank you amit
AmitGajjar 14-Aug-12 6:31am    
welcome, Please mark solution as answered if it helps you.
SQL
For adding items to list view there is overloaded method which takes 3 parameters, with key, name and image index

while retrieving use Find(key) or 
listView1.Items.IndexOfKey(key)

          listView1.Items.Add("key", "Text", 0);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900