We help IT Professionals succeed at work.

ASP GridView invisible cell value

sborchers
sborchers asked
on
2,714 Views
Last Modified: 2008-01-09
I have a GridView with multiple columns, some are invisible, how can I get the value of that invisible field into a textbox or label?  
Comment
Watch Question

Commented:
You can databind the textbox to the appropriate datasource, if your using one...  What are you using?

Jake

Author

Commented:
I only want or need the data from the GridView if they 'Select' it, which moves the data to textboxes that they will edit, then save the changes.  It is reading from a SQL Server database, I could call another stored procedure when they click on the row they want to edit, but I thought since the data is all ready in the GridView (as an Invisible field), i would move that to the textboxes.
Ashley BryantSenior Software Engineer

Commented:
You can only pull over data from the gridview that is either part of the datakeys or visible in the gridview.  This is because those are the only items that the viewstate maintains.  So, either make your invisible fields part of the viewstate, or do a separate query to pull the complete data record that you selected in the gridview.

You could also use a detailsview with the same sqldatasource (or whatever data source you are using) so that they're using the same query string, but I'm pretty sure it will still make another query to the database.
DataGridItem item;
item = MyGrid.Items(intRow);
strName = item.Cells[0].Text().Trim()

if  0th cell contains hidden data then you can fetch values like
strName = item.Cells[0].Text().Trim()

where item is dataGridItem object.. you can get these object from eventarguments of itemselected event of datagrid

REgards
REnju

Commented:
The other option you could use is to get the primary key from the selected row of the gridview, and retrieve the full row from the database or dataset, and then populate any information you need from the datarow, that way, you don't have to worry about data that isn't in your gridview.

Let me know if you need help with that.

Jake
Ashley BryantSenior Software Engineer

Commented:
Does that work with GridView as well, renjurdevan?

I did find this quick article that basically says what you want to do:

http://www.codeproject.com/useritems/Hide_GridView_Column_Cell.asp
If your lazy like me (and most good coders :-) ) just set the width to be 0.  Then you can refer to it, but it does not appear.

Author

Commented:
Jake,
Do you have an example you could share?

Thanks.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Forced accept.

Computer101
EE Admin

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.