Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,
I have grid, in which i have used label to display values in each column.
how can i get values of that label as key(userid) to perform add, delete, edit
I tried
e.CommandArgument.ToString()
, but not giving required reult

Thanks in advance
Posted

Here the simple ans for it

((Label)gv.SelectedRow.FindControl("lblId")).Text
 
Share this answer
 
Comments
dhage.prashant01 18-Apr-11 9:19am    
This line gives me the ans of my question, hope this might help u all.
handle that label value in another column and set that column width=0 so it will not be visible
and get that value from the hidden column.Hope this trick will help to solve ur problem.
 
Share this answer
 
Comments
dhage.prashant01 17-Apr-11 12:29pm    
thanks, but its not the solution m looking for. I want that label value when i click on delete/edit button in rowcommand of grid.
Get the Row, use FindControl method to find the specific label with the id. Then get the Text property of the found control. Label control is not a command control and can't set the command argument.
 
Share this answer
 
Comments
dhage.prashant01 17-Apr-11 12:37pm    
i have tried
gv.colums[0].findcontrol("lbluserid")

but not giving proper values, it always return 1
Albin Abel 17-Apr-11 13:07pm    
You supposed to find the label from rows or columns?
Get the label value - search through the collection that holds the grid to locate the row / column and then perform whatever operations you need to on the value.

You say you tried. Post some code here and someone might be able to help you.
 
Share this answer
 
I hope this will help you
protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
{
    string strUserID =((Label)grdView.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("lbluserid")).Text;
}
 
Share this answer
 
v2
Simply Use datakey to your desired column like this

C++
GridView.DataKeyNames = new string[] { "ID" };


then on
C++
GridView_RowDeleting

or editing command u can write this

C++
int ID = Convert.ToInt32(GridView.DataKeys[e.RowIndex].Value);


Hope this helps
 
Share this answer
 
Hi,

protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
{

Dim index = Convert.ToInt32(e.CommandArgument)
Dim row = ProductsGridView.Rows(index)
Dim labelText = CType(row.FindControl("LabelName"), Label).Text

}

I hope this will help you.
 
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