Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a Gridview with five columns, i want a column index of selected row or cell and i also want selected value of any row or cell

Thanks in advance
Posted
Comments
Suman Zalodiya 1-Jul-13 8:16am    
First of all you should set DataKeyName for the gridview.

hi
check this link may it will help

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcelleventargs.columnindex.aspx


e.ColumnIndex will also work for this.
 
Share this answer
 
visit this link:
http://forums.asp.net/t/1537390.aspx

Hope its helpful..

Thanks
 
Share this answer
 
Hi Ravi,

XML
Please don't forget to add the DataKeyName="PrimaryKeyField" property in the grid view like

<asp:gridview id="Gridview1" run="server" datakeynames="CustID" >


C#
int uid = (int)gvDeleteUser.DataKeys[gvDeleteUser.Rows.RowIndex].Value;




Please check it and let me know in case of any concerns.

And please make it as resolved if it resolves.

Thanks and Regards
Suman Zalodiya
 
Share this answer
 
v2
Please provide us with more concretics when answering such questions, because there are so many kinds of Gridviews in .Net world ;)

And in general your solution is:

gridView.Rows['Index of selected row']['Index or column name of cell you want to get value from']
that in concrete:
gridView.Rows[gridView.SelectedRowIndex]["ID"]

As often values in cells are of type Object, so it needed to convert them after getting.
In some implementations it may be:
gridView.Rows[gridView.SelectedRowIndex].Cells["ID"]

But i think the main idea you have got.
Rows - are collection of rows of Table
and
Cells (or columns) - are collection of cells of Row
 
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