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

Value is " " on event SelectedIndexChanged

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Denis
Top achievements
Rank 1
Denis asked on 30 Nov 2015, 02:31 PM

I tried to get the ID value from selected row in a RadGrid. But what I try, I keep the value " ".
The data is collected by a WCF webservice by the way.

Below the ASP code I use:

<telerik:RadScriptManager ID="RadScriptManager" runat="server" EnableHandlerDetection="false">
        <Scripts>
             
        </Scripts>
    </telerik:RadScriptManager>
 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="gridSimCards">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="gridSimCards" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
 
    <div class="pagetitle"><asp:Literal ID="ltrPageTitle" runat="server" /></div>
 
    <telerik:RadGrid ID="gridSimCards" runat="server" EnableViewState="true" AutoGenerateColumns="false" Skin="Silk" AllowFilteringByColumn="true" AllowPaging="true" PageSize="10" AllowSorting="true"
        OnSelectedIndexChanged="gridSimCards_SelectedIndexChanged">
        <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="true" AllowColumnsReorder="true">
            <Selecting AllowRowSelect="true" />
            <Resizing AllowColumnResize="true" ShowRowIndicatorColumn="true" />
            <DataBinding SelectMethod="GetSimCards"
                Location="../WebServices/GridDataProvider.svc"
                SelectCountMethod="GetSimCardsCount"
                MaximumRowsParameterName="rowCount"
                StartRowIndexParameterName="rowStart"
                SortParameterName="sorter" SortParameterType="List"
                FilterParameterName="filter" FilterParameterType="List"  />
        </ClientSettings>
        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
        <MasterTableView Width="100%" DataKeyNames="ID">
            <Columns>
                <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="#" DataType="System.String"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Provider" HeaderText="Provider" DataType="System.String"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Country" HeaderText="Land" DataType="System.String"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="SIMNumber" HeaderText="SIM-nummer" DataType="System.String"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="TelephoneNumber" HeaderText="Telefoonnummer" DataType="System.String"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ContactPeriodFrom" HeaderText="Contract van" DataType="System.DateTime"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ContractPeriodTill" HeaderText="Contract tot" DataType="System.DateTime"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="InUse" HeaderText="In gebruik" DataType="System.Boolean"></telerik:GridBoundColumn>
            </Columns>
             
        </MasterTableView>
    </telerik:RadGrid>

 

The code below is use to get the value of the selected ID column:

protected void gridSimCards_SelectedIndexChanged(object sender, EventArgs e)
{
    int selectedRowIdx = gridSimCards.SelectedItems[0].ItemIndex;
 
    GridDataItem selectedItem = (GridDataItem)gridSimCards.MasterTableView.Items[selectedRowIdx];
 
    string str = selectedItem["ID"].Text;
}

 

What am I doing wrong, or what am I missing?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 02 Dec 2015, 06:48 AM
Hello Denis,

Here is the answer from the support ticket that you have opened with the same question:

"With client-side binding, the values of the items will be available only on the client-side and it is not possible to retrieve them on a server-side event. With that in mind, if you need to retrieve the values from the selected item you will have to disable the "PostBackOnRowClick", which is initiating the postback, and handle the client-side OnRowSelecting or OnRowSelected events and retrieve the values there:

Best Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
 
Tags
Grid
Asked by
Denis
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or