Really struggling to see the obvious - need to get data from selected row

4 posts, 0 answers
  1. Paul
    Paul avatar
    55 posts
    Member since:
    Nov 2010

    Posted 22 Sep 2011 Link to this post

    I haven't used RadGrid for a while and I am spending a lot of time getting nowhere with something I know should be easy.

    I don't care if I use a ListView or Grid - either will do the job. The datasource is a datasource control that works fine and I can get both a listview and a grid to display the data I want. However;

    1. I only want a max of 1 row selected at a time
    2. I want read the value of some cells/columns in the selected row

    That's it. (2) is the priority.

    I've tried everything I can think of and I've looked at all of the documentation and nothing seems to work. With the grid the grid is displaying the data and I can see that myGird.items has a count =2 but all of the dataItems=null. I'm obviously missing something obvious but I just cannot get anything to work at the moment.
  2. Dan Lehmann
    Dan Lehmann avatar
    103 posts
    Member since:
    May 2011

    Posted 22 Sep 2011 Link to this post

    In the following example note the ClientSettings specifies a javascript function to call in order to get the Customer_id. Also notice where I have ClientDataKeyNames="Customer_id". Without that, can't get the value in javascript.
    <script type="text/javascript">
        function onRowSelected(sender, args) {
            var Customer_id = args.getDataKeyValue("Customer_id");
    <telerik:RadGrid ID="rgCustomers" runat="server" Skin="Vista" AllowSorting="false" AllowFilteringByColumn="false" AllowPaging="true" AllowCustomPaging="true"
        Width="100%" AutoGenerateColumns="false" GridLines="Both"
        ShowFooter="false" ShowHeader="true" ItemStyle-CssClass="trone" AlternatingItemStyle-CssClass="trtwo" SelectedItemStyle-BackColor="Blue" >
        <ClientSettings EnablePostBackOnRowClick="false">
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowSelecting="onRowSelected" />
        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
        <GroupingSettings CaseSensitive="false" />
        <MasterTableView Width="100%" TableLayout="Fixed" GridLines="Both" ClientDataKeyNames="Customer_id">
            <RowIndicatorColumn Visible="true">
                <HeaderStyle Width="20px" />
                <telerik:GridBoundColumn UniqueName="Customer_id" DataField="Customer_id" ReadOnly="true" Visible="false" />
                <telerik:GridBoundColumn HeaderText = "Last" DataField="LastName" ItemStyle-Width="100%" HeaderStyle-Width="100px" />
                <telerik:GridBoundColumn HeaderText = "First" DataField="FirstName" ItemStyle-Width="100%"  HeaderStyle-Width="95px" />
                <telerik:GridBoundColumn HeaderText = "Phone" DataField="Phone" ItemStyle-Width="100%"  HeaderStyle-Width="75px" />
                <telerik:GridBoundColumn HeaderText = "Email" DataField="Email" ItemStyle-Width="100%"  HeaderStyle-Width="105px" />

    Also notice in Clientsettings EnablePostBackOnRowClick="false". Set this to true and handle it in the SelectedIndexChanged in your codebehind.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    55 posts
    Member since:
    Nov 2010

    Posted 06 Oct 2011 Link to this post

    Hi Dan. Sorry for the delay replying.

    At the moment I am not very comfortable with javascript and so I tend to try to find server side solutions. I realise that you can set client side single row selection but just generically configuring a grid so that only a single row can be selected?

    The main aspect of my question was how to get server side visibility of the contents of a row. I have trieded the items collection but just wasn't having any success getting access to the row contents. The documentation seems to suggest that I should just be able to reference data using the column names but that isn't happening.
Back to Top