This is a migrated thread and some comments may be shown as answers.

Getting grid data server side

7 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 17 Apr 2009, 02:29 PM
Hi all

I have a nested gridview, and need to get the values of a GridBoundColunm on postback. 

What I want to do is when a user hits the delete icon it deletes the record, but I cant get a handle in the datakeyvalues, I have to rely on a hidded id field, it's this hidden id field that I have in a grigboudcolumn.

Can somesone show me how please

Andy

7 Answers, 1 is accepted

Sort by
0
Andy Green
Top achievements
Rank 2
answered on 17 Apr 2009, 02:44 PM
I think I have it:

 

Dim item As GridDataItem = DirectCast(rgProfileMain.Items(e.Item.ItemIndex), GridDataItem)

 

 

Dim Observation_ID As String = item("Observation_ID").Text

Andy

 

0
Andy Green
Top achievements
Rank 2
answered on 19 Apr 2009, 09:12 PM
Hi All

I need some help with this.

My code above does return the value of the ID field, but........
It returns the row above the row that is clicked. I have tried this not only with the ID but also the texts fields, if I click on the second row it returns all data for the first row, and if I click on the first row it errors with 'Cannot find a cell bound to column name 'Observation''

Any idea what Im doing wrong.

Andy
0
Shinu
Top achievements
Rank 1
answered on 20 Apr 2009, 06:30 AM
Hi Andy,

Give a try with the following code snippet in the DeleteCommand event and See whether you getting clicked row's data.

VB:
 
 
    Protected Sub RadGrid1_DeleteCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
        'Get the primary key value using the DataKeyValue. 
        Dim ProductID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("Observation_ID").ToString() 
    End Sub 
 


Shinu
0
Andy Green
Top achievements
Rank 2
answered on 20 Apr 2009, 07:30 AM

Running the code as is the line ' Dim ProductID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("Observation_ID").ToString()' Gives the following error:

Object reference not set to an instance of an object.

This is because I cannot use the datasourcenames without it erroring on insert.

If I add Observation ID to the datakeynames it does return the correct row, but when I insert a record in the nested grid I get this error.

'There was a problem extracting DataKeyValues from the datasource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the datasource'

That is why I can use the DatakeyValues but rather use a hidded grid boud column. Why would extracting the value from a grid bound column return the one above, could it be an ordinal problem ie one method is 1,2,3 and the other 0,1,2.

Andy

0
Andy Green
Top achievements
Rank 2
answered on 21 Apr 2009, 10:23 AM
Hi - Hope you enjoyed your breaks yesterday

Is there anyone who can offer any advice on this please. It's the last push before I can release the software.

Andy
0
Princy
Top achievements
Rank 1
answered on 21 Apr 2009, 11:43 AM
Hello Andy Green,

The datakeyvalue does not exist while inserting a new item so when you access the datakeyvalue for an item check if the ownertableview is not in insertmode so as to avoid the error.
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
If Not item.OwnerTableView.IsItemInserted Then 
    Dim ProductID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("Observation_ID").ToString() 
End If 

Thanks
Princy.
0
MANU
Top achievements
Rank 1
answered on 21 Apr 2009, 12:02 PM
Excellent Princy Moluu, SoftInc.

U r Great!!!!!!!!!!!!!

Where is master Shinu??

Love
MANU
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Andy Green
Top achievements
Rank 2
Shinu
Top achievements
Rank 1
Princy
Top achievements
Rank 1
MANU
Top achievements
Rank 1
Share this question
or