GridDropDownColumn context dependent values

10 posts, 1 answers
  1. beth
    beth avatar
    4 posts
    Member since:
    May 2008

    Posted 16 Jun 2008 Link to this post

    Hi,

    I have a rad grid on my web page and I need to do the following.

    - Have a GridDropDownColumn that uses values in other columns in the current row to retrieve a list of appropriate values.

    We are creating a general ledger code builder and the 4th part of the code is dependent on the 1st 3 parts. So on a row by row basis i need to return the context specific values.

    I have a datasource that take two parameters
    1) Type this is set ok
    2) The portion of the code to return appropriate values for.

    How do i pass the values of my columns in to this parameter?
    In my edit form i have used the selecting event to set the parameter, but i can't see how i would do this for the grid.

    Any help much appreciated

    Graham

     

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 17 Jun 2008 Link to this post

    Hi Beth,

    If you need to get your item values before RadGrid is rendered, so that you update other data inside the item, you can do it in the ItemDataBound event handler, provided for the exact purpose of manipulating RadGrid data before rendering. In it, you can get your drop down column in the respective item and set its value based on other item cell values.


    All the best,
    Veli
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. beth
    beth avatar
    4 posts
    Member since:
    May 2008

    Posted 19 Jun 2008 Link to this post

    Hi,

    Thankd for the response, I've tried to use the ItemDataBound event, but the grid will not resolve the data in the first row, when the for first loads, it definitely runs the code for the first record, but it doesn't set the value.
    I'm using the following code

    protected void grdMRU_ItemDataBound(object sender, GridItemEventArgs e)

    {

    if (e.Item is GridDataItem)

    {

    string strGL = e.Item.Cells[4].Text;

    dstNominalNatural.SelectParameters["strGLNum"].DefaultValue = strGL.Substring(0, 6);

    }

    }

    Also it doesn't set the value in the corresponding edit field when the item goes into edit mode.

    Thanks

  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 20 Jun 2008 Link to this post

    Hi Beth,

    Instead of accessing the item cell by index, please try accessing it by the column's unique name:

    GridDataItem item = (GridDataItem)e.Item; 
    string strGL = item["ColumnUniqueName"].Text; 


    Regards,
    Veli
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. beth
    beth avatar
    4 posts
    Member since:
    May 2008

    Posted 20 Jun 2008 Link to this post

    Hi,

    Thanks for the response, the code retrieves the correct value, but it still doesn't set the value for the cell in the first row of the grid.

    Process
    - There is a datasource on the age which has 1 parameter used to get a list of appropriate values for the gl_natural column in the grid.
    -The paramter is the first 6 digits of the gl_code column.
    -SO what I'm doing is using the ItemDataBound event to set the default parameter of the datasource each time a new item is bound to the grid. This
    works only for rows 2 and on, row 1 doesnot set even though the code is run.

    - is this the best way to do this? if so do you know why it isn't working for the first item?
    -- could it be a timing issue or overloading the datasource
    -- we will typically only have 2 or 3 rows in the grid.
    - i now have the edit form working correctly.

    Thanks for you help

  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Jun 2008 Link to this post

    Hi,

    Go through the following help document link.
    Accessing cells and rows

    Princy.
  8. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 20 Jun 2008 Link to this post

    Hi Beth,

    I don't think the ItemDataBound event is the correct place in RadGrid's lifecycle to change data source parameters. The reason for this is that ItemDataBound is fired after the item is bound to data, which means after the required data access for the item. This explains why this approach doesn't work for the first item - simply because the parameter is not set before the item is bound, but is only available for the 2nd and so on items. The best place to initially set this parameter would be the place where you define your data source for RadGrid. Ideally, this is the NeedDataSource event handler, which specifies the data source of RadGrid every time it needs to rebind the data.

    In this way, you make sure that the data source parameter is set before the first item is fetched. Please see how this works for you.

    Sincerely yours,
    Veli
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. beth
    beth avatar
    4 posts
    Member since:
    May 2008

    Posted 20 Jun 2008 Link to this post

    Thanks,

    I've moved the code to the ItemCreated event and it now works .

  10. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Jun 2008 Link to this post

    Hi Beth,

    You can also refer the following help article.
    Distinguishing the major differences between the ItemCreated and ItemDataBound server events

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