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

[Solved] How to run server code after user row click ?

2 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Krzysztof
Top achievements
Rank 1
Krzysztof asked on 06 Jan 2010, 07:35 AM
Hello. Here is what I try to do. A user clicks on the row in the radgrid, and then the code is running on the server. Please note the unusual construction of the radgrid. Is there any way to do this ?

rik:RadGrid ID="gv_umowy" runat="server" DataSourceID="sql_moje_umowy" AutoGenerateColumns="False" 
            GridLines="None" AllowSorting="True">  
            <MasterTableView DataKeyNames="id_umo" DataSourceID="sql_moje_umowy">  
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="nazwa_kh" HeaderText="Kontrahent" HeaderStyle-Width="200px" 
                        ItemStyle-Width="200px">  
                        <HeaderStyle Width="200px"></HeaderStyle> 
                        <ItemStyle Width="200px"></ItemStyle> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="nr_ewidencyjny" HeaderText="Nr umowy AU" HeaderStyle-Width="90px" 
                        ItemStyle-Width="90px">  
                        <HeaderStyle Width="90px"></HeaderStyle> 
                        <ItemStyle Width="90px"></ItemStyle> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="waznosc_umowy" HeaderText="Data obowiÄ…zywania" 
                        DataFormatString="{0: dd-MM-yyyy}" HeaderStyle-Width="90px" ItemStyle-Width="90px">  
                        <HeaderStyle Width="90px"></HeaderStyle> 
                        <ItemStyle Width="90px"></ItemStyle> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="odpowiedzialna" HeaderText="Osoba odpowiedzialna" 
                        HeaderStyle-Width="90px" ItemStyle-Width="90px">  
                        <HeaderStyle Width="90px"></HeaderStyle> 
                        <ItemStyle Width="90px"></ItemStyle> 
                    </telerik:GridBoundColumn> 
                </Columns> 
                <ItemTemplate> 
                    <href="#" target="_blank" onclick="klik('<%#Eval("id_umo")%>')">  
                        <table border="0" align="left" width="100%">  
                            <tr> 
                                <td width="200px">  
                                    <%#IIf(Len(Eval("nazwa_kh")) > 32, Left(Eval("nazwa_kh"), 32) + "...", Eval("nazwa_kh"))%> 
                                </td> 
                                <td width="90px">  
                                    <%#Eval("nr_ewidencyjny")%> 
                                </td> 
                                <td width="90px">  
                                    <%#IIf(Eval("waznosc_umowy") = "1900-01-01", "bezterminowa", String.Format("{0:d}", Eval("waznosc_umowy")))%> 
                                </td> 
                                <td width="90px">  
                                    <%#Eval("odpowiedzialna")%> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td colspan="5" width="100%">  
                                    <b> 
                                        <%#Eval("opis")%></b>  
                                </td> 
                            </tr> 
                        </table> 
                    </a> 
                </ItemTemplate> 
            </MasterTableView> 
            <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowDragToGroup="True">  
                <Selecting AllowRowSelect="True" /> 
                <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
            </ClientSettings> 
        </telerik:RadGrid> 

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jan 2010, 08:54 AM
Hello,

Set the ClientSettings -> EnablePostBackOnRowClick property of the grid to True (the default value is false) in order to invoke a postback when user clicks an arbitrary cell in a grid row.

aspx:
 
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" 
        OnItemCommand="RadGrid1_ItemCommand"
        <MasterTableView AutoGenerateColumns="False" EditMode="InPlace" CommandItemDisplay="Top" 
            DataSourceID="SqlDataSource1" DataKeyNames="CustomerID"
            <Columns> 
              . . . 
            </Columns> 
        </MasterTableView> 
        <ClientSettings EnablePostBackOnRowClick="true"
        </ClientSettings> 
</telerik:RadGrid> 

cs:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "RowClick"
        { 
            Response.Write("RowClick"); 
            // Your code 
        } 
    } 

Also checkout the following documentation to know more about this:
Making postback/ajax request on client row click

-Shinu.
0
Krzysztof
Top achievements
Rank 1
answered on 06 Jan 2010, 09:24 AM
Works great! thank you very much.
Tags
Grid
Asked by
Krzysztof
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Krzysztof
Top achievements
Rank 1
Share this question
or