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

RadGrid row selection event

4 Answers 582 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fousto
Top achievements
Rank 1
Fousto asked on 19 Feb 2014, 09:29 AM
Hi,
I have this grid:

<asp:updatepanel runat="server">
        <ContentTemplate>
        <telerik:RadGrid ID="actGrid" runat="server" AllowFilteringByColumn="True"
            AllowSorting="True" CellSpacing="0" CssClass="gridBlock" GridLines="None"
                AutoGenerateColumns="false" AllowPaging="true" ShowHeader="True">
            <ClientSettings>
            <%--<ClientEvents OnCellSelected="OnRowSelection"/>--%>
            <Selecting AllowRowSelect="True" />
            </ClientSettings>
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView TableLayout="Fixed" PageSize="5">
                <Columns>
                    <telerik:GridBoundColumn ItemStyle-Font-Bold="true" DataField="Description"/>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        </ContentTemplate>
        </asp:updatepanel>



I'm trying to add an event to update other elements (checkboxes and textboxes) in the page on row selection using the ClientEvents OnCellSelected (I've commented it), but when I uncomment this part of code I cannot select any rows anymore and no event is firing.

Any suggestions?

Thx










4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Feb 2014, 09:55 AM
Hi Fousto,

Make sure you have written the javascript function to handle the OnCellSelected event.
Please have a look at the following code snippet:

ASPX:
<telerik:RadGrid ID="actGrid" runat="server">
    <ClientSettings>
        <ClientEvents OnCellSelected="OnRowSelection" />
        <Selecting AllowRowSelect="True" CellSelectionMode="Column" />
    </ClientSettings>  
    <MasterTableView TableLayout="Fixed" PageSize="5">
        <Columns>
            <telerik:GridBoundColumn ItemStyle-Font-Bold="true" DataField="OrderID" HeaderText="OrderID" />
            <telerik:GridBoundColumn ItemStyle-Font-Bold="true" DataField="ShipVia" HeaderText="ShipVia" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


JS:
<script type="text/javascript">
    function OnRowSelection(sender, eventArgs) {
        var Rows = eventArgs.get_gridDataItem();
        var columnName = eventArgs.get_column().get_uniqueName();
        var data = Rows.get_cell(columnName);
        alert(data.innerHTML);
    }
</script>

Thanks,
Princy.
0
Fousto
Top achievements
Rank 1
answered on 19 Feb 2014, 01:11 PM
Thanks Princy,
there was an error on the javascript function.
Another question, the script must be a javascript (<script type="text/javascript">) or it can be also a <script type="text/C#">?
I mean something like this

<script type="text/C#">
              protected void OnRowSelection(object sender, eventArgs e) {
                   
              }
</script>

0
Princy
Top achievements
Rank 2
answered on 20 Feb 2014, 04:54 AM
Hi Fousto,

I'm not clear about your question. The OnCellSelected event is a client side event of the RadGrid hence it can be only inside a JavaScript (<script type="text/javascript">). Please elaborate on your scenario if this didn't help.

Thanks,
Princy
0
Fousto
Top achievements
Rank 1
answered on 20 Feb 2014, 08:38 AM
You answered perfectly my question, I was just hoping as a newbie that client side event could be written also in C# code.

Thanks
Tags
Grid
Asked by
Fousto
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Fousto
Top achievements
Rank 1
Share this question
or