This is a migrated thread and some comments may be shown as answers.

Trigger a server-side event with client-side onclick

6 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 28 Sep 2009, 12:43 PM

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.

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 28 Sep 2009, 01:08 PM
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.
0
James O'Brien
Top achievements
Rank 1
answered on 07 Oct 2009, 09:11 PM
Can you post an example?
0
Princy
Top achievements
Rank 1
answered on 08 Oct 2009, 05:43 AM
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.
0
James O'Brien
Top achievements
Rank 1
answered on 08 Oct 2009, 01:27 PM
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;   
        }   
    }  
0
Schlurk
Top achievements
Rank 2
answered on 08 Oct 2009, 07:40 PM
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;  
            ....  
        }  
    }  

0
John
Top achievements
Rank 1
answered on 09 Sep 2014, 10:54 PM
Thanks...It worked for me!
Tags
Grid
Asked by
Erik
Top achievements
Rank 1
Answers by
Vlad
Telerik team
James O'Brien
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Schlurk
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or