• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 532
  • Last Modified:

How do I get a Gridview row value into a variable or label?

How do I get a Gridview row value into a variable or label?

Tried this bit it didnt work.



Label wsID = (Label)(Gridview1.Row.Findcontrol(wsID));
Label1.Text = wsID.Text

Open in new window

0
bmanmike39
Asked:
bmanmike39
  • 4
  • 4
1 Solution
 
smartali89Commented:
use this..

label1.text = datagridview.row[rowindex].cells[cellindex].value.tostring();
0
 
bmanmike39Author Commented:
i don't get the row option
0
 
smartali89Commented:
Do you get "Items" option in the list?

and which version of .net are you using ?
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
bmanmike39Author Commented:
Maybe Im wrong but i was assuming that  datagridview reference i was to substitute my Gridview name for.

But i dont get an item option  nor a row, just Rows
0
 
smartali89Commented:
ok, so you have Rows option, then it should have Cells option as well, use this code and it should work.
If you are using template in datagridview you will see items instead of rows.
Label1.Text = MyGrid.Rows[rowIndex].Cells[columnIndex].Text;

// and for Items

Label1.Text = MyGrid.Items[rowIndex].Cells[columnIndex].Text;

Open in new window

0
 
bmanmike39Author Commented:
this is what i have
Label1.Text = Gridview1.Rows[rowIndex].Cells[columnIndex].Text;

I get an error message rowindex does not exist in the current context  I also get it for the columIndex  am i missing a using statement?


0
 
smartali89Commented:
replace rowindex, columnindex with the index of row and column from which u want to retrieve the value,

for example if the text you want to retrieve is in 2nd row and 3rd column, then

the code will be:
Label1.Text = Gridview1.Rows[2].Cells[3].Text;

Open in new window

0
 
bmanmike39Author Commented:
excellent

Thanks!!!
0
 
CB_ThirumalaiCommented:
In which event you want the value of control in Gridview.  It will be easy to post solution if you say specific condition on which you need the value.  for example, if it is in any of the GridView's events, then you have GridViewRowEventArgs e.  From this you get the entire Row you want to access.  e.Row.Cells[columnIndex], where columnIndex is any column from first, represented as 0 to the number of coulmns-1.

so, for first column, you get it as, e.Row.Cells[0].Controls, will give you the controls collection.  Normally the first control will be the Literal control.

Just a suggestion. :-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now