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

RadGrid Select Row

5 Answers 1488 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 28 Mar 2014, 07:10 PM
So I've seen this thread answered over and over and according to what I've read, this should work no problem. But it's not. I just want to be able to select a record. I also want to enable the rowHoverStyle.

Nothing works. Not sure if it's a setting in my web.config or what. The link below shows that it isn't working and my code is below. The label is supposed to show the row data of the clicked row.

http://www.mydealbinder.com/test.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
       <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
                    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" OnPreRender="RadGrid2_PreRender"
                        CellSpacing="0" GridLines="None" Skin="Web20" ShowHeader="False" OnSelectedIndexChanged="RadGrid2_SelectedIndexChanged">
 
                        <ClientSettings Selecting-AllowRowSelect="true" EnableRowHoverStyle="true">
                            <Selecting AllowRowSelect="true" />
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                            <ClientEvents OnRowMouseOver="RowMouseOver" />
                        </ClientSettings>
                         
                        <MasterTableView DataKeyNames="ntsID">
                                                        
                            <Columns>
                             
                                <telerik:GridBoundColumn DataField="ntsID" DataType="System.Int32"
                                    Display="False" FilterControlAltText="Filter column column" UniqueName="column">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Expr2"
                                    FilterControlAltText="Filter column1 column" UniqueName="column1">
                                </telerik:GridBoundColumn>
                            </Columns>
                             
                        </MasterTableView>
                         
 
                    </telerik:RadGrid>
                 
                
                    <br />
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                 
                
    </telerik:RadAjaxPanel>
    </div>
    </form>
</body>
</html>

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 Mar 2014, 08:52 AM
Hi James,

You should set the EnablePostBackOnRowClick="true" property to get the selected rows code behind.

ASPX:
<ClientSettings Selecting-AllowRowSelect="true" EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">

C#:
protected void RadGrid2_SelectedIndexChanged(object sender, EventArgs e)
{
    GridDataItem selectedItem = (GridDataItem)RadGrid2.SelectedItems[0];
    string value = selectedItem.GetDataKeyValue("ntsID").ToString();
    Label1.Text = value;
}

Thanks,
Princy
0
James
Top achievements
Rank 1
answered on 31 Mar 2014, 08:11 PM
[quote]Princy said:Hi James,

You should set the EnablePostBackOnRowClick="true" property to get the selected rows code behind.

ASPX:
<ClientSettings Selecting-AllowRowSelect="true" EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">

C#:
protected void RadGrid2_SelectedIndexChanged(object sender, EventArgs e)
{
    GridDataItem selectedItem = (GridDataItem)RadGrid2.SelectedItems[0];
    string value = selectedItem.GetDataKeyValue("ntsID").ToString();
    Label1.Text = value;
}

Thanks,
Princy[/quote]

Didn't do the trick. Notice on http://mydealbinder.com/test.aspx how nothing happens onmouseover. The rows should highlight and when I click a row, it should be selected. It's as if the whole radgrid is disabled.
0
Princy
Top achievements
Rank 2
answered on 01 Apr 2014, 03:53 AM
Hi James,

I tried your code it works fine when I set EnablePostBackOnRowClick property to get the selected items. I see that you have a client event OnRowMouseOver, but i dont see it defined in your code. Please remove it if you are not using it. Here is the full code I tried.

ASPX:
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"        CellSpacing="0" GridLines="None" Skin="Web20" ShowHeader="False" OnSelectedIndexChanged="RadGrid2_SelectedIndexChanged">
        <ClientSettings Selecting-AllowRowSelect="true" EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
        </ClientSettings>
        <MasterTableView DataKeyNames="OrderID">
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32" Display="False" FilterControlAltText="Filter OrderID column" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ShipCity" FilterControlAltText="Filter ShipCity column" UniqueName="ShipCity">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</telerik:RadAjaxPanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT  * FROM [Orders]"></asp:SqlDataSource>

C#:
protected void RadGrid2_SelectedIndexChanged(object sender, EventArgs e)
{
  GridDataItem selectedItem = (GridDataItem)RadGrid2.SelectedItems[0];//accessing selected row
  string value = selectedItem.GetDataKeyValue("OrderID").ToString();
  Label1.Text = value;
}

CSS:
<%-- If you want to set row hover color--%>
<style type="text/css">
.RadGrid_Web20 .rgHoveredRow
{
  background-color: Blue !important;
  background-image: none !important;
}
</style>

Thanks,
Princy
0
joel
Top achievements
Rank 1
answered on 05 Sep 2014, 10:57 PM
hi im new to this and using vb.net, i dont see the EnablePostBackOnRowClick in the property to set true .pls how can i select a radgrid row to show texts in a texrbox.
thanks in advance.
0
Angel Petrov
Telerik team
answered on 10 Sep 2014, 12:32 PM
Hello,

For your convenience I have assembled a small website that illustrates how one can set the text of an ASP TextBox when clicking on a row in a RadGrid. There are two different patterns one can use to achieve the desired goal.
  1. Setting the text on the server(illustrated in Default.aspx). Note that when following this approach one should set the EnablePostBackOnRowClick property from the ClientSettings to true.
  2. Setting the text on the client(illustrated in Default2.aspx). Here one can use the client RowClick event and set the value in the textbox using JavaScript.

Hope the example provided proves helpful.


Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
James
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
James
Top achievements
Rank 1
joel
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or