Getting grid data server side

8 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 17 Apr 2009 Link to this post

    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
  2. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 17 Apr 2009 Link to this post

    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

     

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 19 Apr 2009 Link to this post

    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
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Apr 2009 Link to this post

    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
  6. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 20 Apr 2009 Link to this post

    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

  7. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 21 Apr 2009 Link to this post

    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
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Apr 2009 Link to this post

    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.
  9. MANU
    MANU avatar
    1 posts
    Member since:
    Apr 2009

    Posted 21 Apr 2009 Link to this post

    Excellent Princy Moluu, SoftInc.

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

    Where is master Shinu??

    Love
    MANU
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017