Click here to Skip to main content
14,773,207 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hey everyone.

I have a DataTable which is bind to dataGridview in my code.

When I get datas from database, the gridview works fine. it fills with data.
What I want to do is getting the index(actually the value of the Primary key) of the of the specified row.

How can I do it?
Me best regards...
Posted
Updated 19-Dec-11 1:03am
v2

public static int Getindex(string row,DataTable dt)
        {
            int id=0;
            string rowvalue = row;
            try
            {
                id = (from DataRow dr in dt.Rows
                      where (string)dr["Description"] == rowvalue
                      select (int)dr["Id"]).FirstOrDefault();
            }
            catch(Exception ex)
            {
                //Response.Write(ex.Message);
            }
            return id;
        }


this linq query might solve your problem,

hope this helps,
--G--
   
Set datakeyname to select particular row form DB...
GO THRU THIS LINK FOR MORE DETAILS ON ADD AND EDIT..


gridview-datakey-value
Edit_update
   
v2

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