GridView: retrieving data from not visible columns

LadyReader1

Member
Joined
Apr 11, 2007
Messages
10
Programming Experience
10+
2 problems, maybe related (VB.net 2005):
I have a GridView with 7 columns, 2 of which are set to not Visible. One of these is a unique identifier for the row's record and the other is a non-unique identifier for the batch the item falls into (there can be multiple rows per batch and multiple batches displayed in this GridView). Originally I also had a "Delete" button, which worked fine. Then I added another command button for "Select". The data is being retrieved thru a SQLDataSource using sprocs.

I am using the RowCommand event to test for e.CommandName. Initially, while developing, I set Visible=True for both the Unique_ID and the Batch_ID columns and I was able to retrieve the value of Batch_ID with:

VB.NET:
MyGridView.Rows(e.CommandArgument).Cells(1).Text

and the Select command was able to be processed. But when I reset the Batch_ID column to not Visible, the reference came up as an empty string. Question 1: why is this value unavailable when the column is not visible?

I added Batch_ID to the list of DataKeys, along with the unique row identifier, and then I was able to retrieve Batch_ID with:

VB.NET:
MyGridView.DataKeys.Item(e.CommandArgument).Values(1)

This gave me what I wanted but then I retested the Delete functionality and that failed, telling me I had too many arguments for the sproc. Question 2: Is this related to the fact that I have multiple items specified in the DataKey collection? How do I get around this?

Also, I need to be able to intercept the Delete process so I can test to see if the SQL record has any child records. If it does, I want to cancel the delete, so I can't allow the SQLDataSource to handle the Delete by itself. Question 3: do I need to stop using the SQLDataSource and just code it myself?


Thank you for any help you can offer.
 
1) When an object's visible property is set to False, ASP.NET doesn't generate the HTML for that object.

2) Yes. To get around it, reference the datasource instead of the grid cell.

3) You can either use an ObjectDataSource and handle the child records in the object behind the ObjectDataSource or continue to use a stored procedure and handle the child records in the stored procedure.
 
Back
Top