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

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

3 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 22 Sep 2011, 09:22 PM
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.

3 Answers, 1 is accepted

Sort by
0
Dan Lehmann
Top achievements
Rank 1
answered on 22 Sep 2011, 10:57 PM
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">
//<![CDATA[
     
    function onRowSelected(sender, args) {
        var Customer_id = args.getDataKeyValue("Customer_id");
    }
 
//]]>
</script>
 
<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" />
    </ClientSettings>
     
    <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
    <GroupingSettings CaseSensitive="false" />
    <MasterTableView Width="100%" TableLayout="Fixed" GridLines="Both" ClientDataKeyNames="Customer_id">
        <RowIndicatorColumn Visible="true">
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <Columns>
            <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" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

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

Dan
0
Paul
Top achievements
Rank 1
answered on 06 Oct 2011, 01:54 PM
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.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Dan Lehmann
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Share this question
or