Trigger a server-side event with client-side onclick

7 posts, 0 answers
  1. Erik
    Erik avatar
    4 posts
    Member since:
    Apr 2009

    Posted 28 Sep 2009 Link to this post


    I like the ability to select a row just by clicking anywhere on it, but I don't know how to run a server-side event when it happens. 

    Does anyone have an example of how to run a server-side event after clicking anywhere on a row in a RadGrid?  I don't really have room for a select button, so I'm looking for other options.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 28 Sep 2009 Link to this post

    Hello Erik,

    If you set ClientSettings.EnablePostBackOnRowClick to true you can catch this on the server using ItemCommand - "RowClick" in this case.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. James O'Brien
    James O'Brien avatar
    19 posts
    Member since:
    Oct 2009

    Posted 07 Oct 2009 Link to this post

    Can you post an example?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2009 Link to this post

    Hi James,

    Here's the code to fire a server side event on clicking on a row:
    aspx:
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" DataSourceID="SqlDataSource1" OnItemCommand="RadGrid1_ItemCommand">                   
           <MasterTableView DataSourceID="SqlDataSource1">                     
           </MasterTableView>   
           <ClientSettings EnablePostBackOnRowClick="true">                   
               <Selecting AllowRowSelect="True" />                            
           </ClientSettings>                 
    </telerik:RadGrid>   

    c#:
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "RowClick"
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                .... 
            } 
        } 

    Thanks
    Princy.
  6. James O'Brien
    James O'Brien avatar
    19 posts
    Member since:
    Oct 2009

    Posted 08 Oct 2009 Link to this post

    Getting GridCommandEventArgs could not be found. I'm binding the datasource on the back-end.

    <telerik:RadGrid ID="RadGridProduct" runat="server" AutoGenerateColumns="False"   
        GridLines="None" AllowMultiRowSelection="True" ShowHeader="False"   
        BorderStyle="None" Skin="Web20" ForeColor="#3399CC" Font-Bold="False"   
        Font-Italic="False" Font-Names="Verdana" Font-Overline="False"   
        Font-Strikeout="False" Font-Underline="False" 
    OnItemCommand="RadGridProduct_ItemCommand">                                         
        <AlternatingItemStyle Font-Bold="False" Font-Italic="False"   
            Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
            ForeColor="#3399CC" Wrap="True" /> 
        <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"   
            Font-Strikeout="False" Font-Underline="False" ForeColor="#3399CC" Wrap="True" /> 
        <MasterTableView Font-Bold="False" Font-Italic="False" Font-Names="Verdana"   
            Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Font-Size="11px">  
            <RowIndicatorColumn><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn>  
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridClientSelectColumn Display="false" UniqueName="columnBlank">  
                </telerik:GridClientSelectColumn> 
                <telerik:GridBoundColumn DataField="Products" UniqueName="colProductSelect"   
                    HeaderButtonType="None">  
                </telerik:GridBoundColumn> 
            </Columns> 
            <ItemStyle Font-Bold="False" Font-Italic="False"   
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                ForeColor="#3399CC" Wrap="True" /> 
            <AlternatingItemStyle Font-Bold="False" Font-Italic="False"   
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False"   
                ForeColor="#3399CC" Wrap="True" /> 
            <EditItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"   
                Font-Strikeout="False" Font-Underline="False" Wrap="True"   
                BackColor="Black" ForeColor="White" /> 
        </MasterTableView> 
        <SelectedItemStyle Font-Bold="True" Font-Italic="False" Font-Overline="False"   
            Font-Strikeout="False" Font-Underline="False" Wrap="True"   
            ForeColor="Maroon" BackColor="Silver" /> 
        <ClientSettings EnableRowHoverStyle="False" EnablePostBackOnRowClick="true" > 
            <Selecting AllowRowSelect="True" /> 
        </ClientSettings>                                          
    </telerik:RadGrid> 
    protected void RadGridProduct_ItemCommand(object source, GridCommandEventArgs e)   
        {   
            if (e.CommandName == "RowClick")   
            {   
                string item = (string)e.Item;   
            }   
        }  
  7. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 08 Oct 2009 Link to this post

    The only thing I can think of is to include Telerik.Web.UI in front of the GridCommandEventArgs:

     
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
        {  
            if (e.CommandName == "RowClick")  
            {  
                GridDataItem item = (GridDataItem)e.Item;  
                ....  
            }  
        }  

  8. John
    John avatar
    43 posts
    Member since:
    Aug 2014

    Posted 09 Sep 2014 in reply to Schlurk Link to this post

    Thanks...It worked for me!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017