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
Dim item As GridDataItem = DirectCast(rgProfileMain.Items(e.Item.ItemIndex), GridDataItem)
Dim Observation_ID As String = item("Observation_ID").Text
Andy
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
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 Object, ByVal 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
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
Is there anyone who can offer any advice on this please. It's the last push before I can release the software.
Andy
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.
U r Great!!!!!!!!!!!!!
Where is master Shinu??
Love
MANU