Setting Grid SelectedValue

5 posts, 0 answers
  1. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 03 Oct 2010 Link to this post

    If I have:

    var radGrid = (RadGrid)source;

     

     

    var selectedValue = radGrid.SelectedValue.ToString();

     

     

    (it happens to be an int)

    And if I then throw that selectedValue to another grid on another page view a querystring redirect, what's the most efficient way to select the relevant grid row (supposing that row exists with the equivalent value) given that SelectedValue doesn't have a Set accessor?

    Thanks,
    Richard

     

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Oct 2010 Link to this post

    Hello Richard,

    I used following code to get the SeletedValue in code behind and used the value for creating the url query string.

    C#:

    string
    selectedValue = RadGrid1.SelectedValue.ToString();



    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 04 Oct 2010 Link to this post

    Hi Shinu, you missed the point of the question (my fault as I just brain-dumped). I'm interested in what comes after:

    "what's the most efficient way to select the relevant grid row (supposing that row exists with the equivalent value) given that SelectedValue doesn't have a Set accessor?"

    I want to set the selected value based on ther previously retrieved value from SelectedValue, which I sent to the page in a querystring.

    Getting it is no problem but how do I select that row based on the value, i.e. how to do:

    RadGrid1.SelectedValue = queryStringValue;

    Best,
    Richard
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Oct 2010 Link to this post

    Hi Richard,


    In ItemDataBound event of the grid, check for the DataKeyValue and select the corresponding row.

    Code behind:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            if (item.GetDataKeyValue("CustomerID").ToString() == queryStringValue)
            {
                item.Selected = true;
            }
        }
    }


    Hope this helps,
    Shinu.
  6. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 06 Oct 2010 Link to this post

    Hi, thanks for sticking with me :)

    Your solution will work, I think.

    But I realised I needed something more complicated (I have multiple parent / child grids), so I am putting the values into session variables and then checking for them in the destination page.

    I haven't quite worked out what I do next but that's another story!

    Wouldn't it be nice to just have a set accessor on SelectedValue?

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