Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2005, 12:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default GridView hidden field access

Hello,

I have a bound field set to visible="false". I have a custom command button, which posts back and I want to get the value of this field that is set to visible="false". Basically, this field is an ID field, and I don't want to show it in the gridview, but I want to be able to access the value. I have this code in the RowCommand event:


Protected Sub gvwTables_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles gvwTables.RowCommand

If (e.CommandName = "Columns") Then

Dim intRow As Integer = CType(e.CommandArgument, Integer)

Dim objRow As GridViewRow = CType(sender, GridView).Rows(intRow)

If (Not IsNothing(objRow)) Then

Response.Write(objRow.Cells(2).Text)

End If

End If

End Sub

But I can't get the value through the Text property. I have the column set up as:


<asp:BoundField DataField="StructureID" HeaderText="Structure ID" Visible="False" DataFormatString="{0}" SortExpression="StructureID" />

Should I be able to access this field through the text property as such? Nothing gets returned but I know a value exists (tested the underlying stored procedure. If not, what do I need to do?

Thanks.

Brian
__________________
Brian
 
Old August 7th, 2005, 07:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Brian,

I ran a few tests and I am seeing the exact same thing. I was expecting that the column would be there, with its value in the cells. I don't know a way around this with your current setup.

However, can't you use the DataKeys collection for this? If the field is an ID, the DataKeys collection would make sense. Alternatively, you could bind the CommandArgument to the ID....

HtH,

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Hymn Of The Big Wheel by Massive Attack (Track 9 from the album: Blue Lines) What's This?
 
Old September 21st, 2006, 01:54 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian,

I know you can use the following to retrieve the underlying data in the hidden field in the RowDataBound event:

System.Web.UI.DataBinder.Eval(e.Row.DataItem, "StructureID")

I have not tested it in the RowCommand event but I don't know why it would not work there also.

Sean







Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView Hidden DateTime Column date conversion babuman ASP.NET 2.0 Professional 0 February 1st, 2007 06:22 PM
pass value to the hidden field Dejitan ASP.NET 1.0 and 1.1 Basics 4 December 21st, 2006 03:13 AM
Hidden Field value error - PLEASE HELP jroxit Classic ASP Basics 5 September 18th, 2006 05:46 AM
Hidden field ashoka_klt ASP.NET 1.0 and 1.1 Basics 1 September 6th, 2006 07:12 AM
How to assign a value to a hidden field? Edward King Javascript How-To 1 May 3rd, 2004 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.