Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to be able to get a selected row from a grid view in asp.net.

basically my last column is a link column and whenever clicking the link I need to get the value of the first column (which is also a hidden column).

So here is and example :

ID (hidden)| Name | surname | link
----------------------------------------
0 | Alex | Garrix | Change


so when clicking change, I need to find the hidden column of [0] when a value in the row is selected, but asp.net does not have the selectedrow.column[0].item.Value (which should then be 0) option, so how can I achieve this in asp.net?


Kind Regards
Posted

1 solution

fisrt Add Gridview select button
when u r binding gridview that time store ur data table in viewState{"data"]

Grid Have row command evevnt

protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
{
C#
if (e.CommandName == "Select")
            {
                int num = Convert.ToInt32(e.CommandArgument);

// u will get selected row number in num
//suppose ID column present in data table now u can easily fetch value using following
DataTable dt=ViewState["data"] as DataTable;
string s=dt.Rows[num]["ID"].toString();
}
}
 
Share this answer
 
Comments
Member 9374423 18-Feb-14 7:29am    
This is also not working, it doesn't work on any rows, please elaborate more on the "View State"

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