Click in a radgrid.

2 posts, 1 answers
  1. Pierre
    Pierre avatar
    56 posts
    Member since:
    Jun 2016

    Posted 19 Aug Link to this post

    Hi,

    I need to click on some link in my rad grid.

    I have 2 like per row.

    on each link im using the following code till i get an answer:

    <telerik:GridHyperLinkColumn   
         UniqueName ="LinkRpt"
         DataTextFormatString="S/N {0} "
         DataTextField="UsrSN"
         DataNavigateUrlFields="CaseID"
         DataNavigateUrlFormatString="~/Site/mypage.aspx?var={0}"
         HeaderText="Repport link" >
    </telerik:GridHyperLinkColumn>

     

    As you can see im using " Request.QueryString["var"] ".
    But i want the var to be in Session. Because this 'var' is a sensitive data.

    I know how to put things in session. Session["field1"] = "value1";

    But  i can't do that with a GridHyperLinkColum because there is no OnClick event.
    Its the same for the GridButtonColumn.
    So i guess i have to use GridTemplateColumn with a RadButtonin it.

    <telerik:GridTemplateColumn >
        <ItemTemplate>
            <telerik:RadButton
                ID="RadButton1"
                runat="server"
                Text="See Repport."
                OnClick="RadButton1_Click" >
            </telerik:RadButton>
        </ItemTemplate>
    </telerik:GridTemplateColumn>

    In this RadButton1_Click, what should i do to get the CaseID of the row clicked.

    How do i navigate to my "~/Site/mypage.aspx" ?
    if i use Javascript:

    function OnClientClicking(button, args) {
                    window.location = button.get_navigateUrl();
                    args.set_cancel(true);
                }

    with the OnClientClicking how do i set things in session ?

     

    Any suggestion will be appreciated.

    Regards,
    Pierre.

     

     

     

  2. Answer
    Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 24 Aug Link to this post

    Hello Pierre,

    Generally, you can pass the ID in query string and use it to get the rest of the data from your database in the opened web page, similar to this live sample:
    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window

    ​You can find additional samples here:
    http://www.telerik.com/forums/context-menu---open-a-pop-up#Qe9fJgzWrE2DhYPWX7OkCQ

    And check the explanation provided in this post:
    http://www.telerik.com/forums/open-report-link-using-unique-row-id#eupACGJdv0mBbLYsQEvMdQ

    In your case, however, you need to use Session, which requires abandoning the javascript QueryString approach and using server-side configuration on the code-behind. You can do that using the following steps:

    1. Use the OnClick event handler of the button.
    2. Get a reference to the GridDataItem using (sender as RadButton).NamingContainer.
    3. Use GetDataKeyValue() method to extract the record ID:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values

    4. Save the ID in a Session variable.
    5. Access the saved value in the new page.

    I am also sending 2 sample RadGrid web sites to demonstrate:
    1. Various ways of declaring link columns
    2. Practical implementation with Session variables.

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top