Change EditText based on data in row

5 posts, 1 answers
  1. TechSavvySam
    TechSavvySam avatar
    38 posts
    Member since:
    Jul 2009

    Posted 12 Nov 2012 Link to this post

    I have a RadGrid with a DetailTable in it.  When I expand a row in the MasterView to show the Detail, I want to change the detail row's Edit link text based on the data in the detail row.

    For example if the row has col1="Blah", then I want the edit text to be "Edit Blah" instead of "Edit".

    What's the easiest way to do this?
  2. Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 13 Nov 2012 Link to this post

    use the same functionality that sets the focus on a quantity textbox
    in the ItemDataBound event handler of the grid
    make sure it's the edit item
            Dim geItem As GridEditableItem = Nothing
            Dim rntbQty As RadNumericTextBox

            If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
                geItem = DirectCast(e.Item, GridEditableItem)
                ' hard coded location
                rntbQty = CType(geItem.Cells(1).FindControl("rntbQty"), RadNumericTextBox)
                rntbQty.Focus()
            End If

    cast the e.item, go to the appropriate cells to find the LinkButton and the other control, then set the Text property of the button
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Nov 2012 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    C#:
    protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
    {
     if (e.Item is  GridDataItem &&  e.Item.OwnerTableView.Name == "DetailTable1")
     {
       GridDataItem dataitem = (GridDataItem)e.Item;
        if (dataitem["UniqueName"].Text == "text")
        {
            LinkButton link = (LinkButton)dataitem["EditColumn"].Controls[0];
            link.Text = "some text";
        }
     }
    }

    Thanks,
    Shinu.
  5. Elliott
    Elliott avatar
    391 posts
    Member since:
    May 2010

    Posted 14 Nov 2012 Link to this post

    Sam - pay no attention to my snippet
    Shinu (again!) has corrected my code

    thanks
  6. TechSavvySam
    TechSavvySam avatar
    38 posts
    Member since:
    Jul 2009

    Posted 14 Nov 2012 Link to this post

    Thanks Shinu,

    You got me close enough that I was able to tweak it for my environment.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017