RadGrid Losing Row Selection on postback

4 posts, 0 answers
  1. Manav
    Manav avatar
    3 posts
    Member since:
    Apr 2016

    Posted 10 May Link to this post

    I am using a radGrid which is inside an RadAjaxPanel.  I want to capture the DataKey value of Selected Row on a button Click Outside the Grid.   Though the button is also contained in the same RadAjaxPanel.   But Everytime I click the button, It returns 0 value for selected row.  I have tried using following code. 

     

     Protected Sub btnUpload_Click(sender As Object, e As EventArgs)
            Dim PersonEducationID As Long = -1      

            For Each item As GridDataItem In radEducationDetail.MasterTableView.Items
                If item.Selected Then
                    Dim strKey As String = item.GetDataKeyValue("ID").ToString()
                    PersonEducationID = strKey
                End If
            Next
        End Sub

     

    Following is the design code for my grid

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">

                    

                    <telerik:RadGrid ID="radEducationDetail" AllowAutomaticUpdates="false" AllowAutomaticDeletes="true" AllowAutomaticInserts="false" OnItemDataBound="radEducationDetail_ItemDataBound" DataSourceID="sqlEducation"
                        AllowSorting="True" AllowPaging="True" runat="server" PageSize="50" Skin="WebBlue" MasterTableView-DataKeyNames="ID" AutoGenerateColumns="false" ShowGroupPanel="false"
                        EnableHierarchyExpandAll="false" EnableLinqExpressions="false" GridLines="None">
                        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                        <MasterTableView Width="100%" CommandItemDisplay="Top" Font-Bold="true" DataSourceID="sqlEducation" DataKeyNames="ID" AutoGenerateColumns="false" ShowGroupFooter="true">
                            <CommandItemSettings
                                AddNewRecordText="Add Education Detail"
                                RefreshImageUrl="../../Images/Refresh.png" />
                            <Columns>

                                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" SortExpression="ID" HeaderStyle-Font-Bold="true" ItemStyle-Font-Bold="false" Visible="false" />

                                <telerik:GridBoundColumn DataField="ProviderName" HeaderText="Provider Name" UniqueName="ProviderName" SortExpression="ProviderName" HeaderStyle-Font-Bold="true" ItemStyle-Font-Bold="false" />

                                <telerik:GridBoundColumn DataField="ProgramName" HeaderText="Program Name" UniqueName="ProgramName" SortExpression="ProgramName" HeaderStyle-Font-Bold="true" ItemStyle-Font-Bold="false" />

                                <telerik:GridBoundColumn DataField="EducationLevel" HeaderText="Education Level" UniqueName="EducationLevel" SortExpression="EducationLevel" HeaderStyle-Font-Bold="true" ItemStyle-Font-Bold="false" />

                                <telerik:GridBoundColumn DataField="StartDate" HeaderText="Start Date" SortExpression="StartDate" UniqueName="StartDate" DataType="System.DateTime" DataFormatString="{0:M/d/yyyy}" HeaderStyle-Font-Bold="true" ItemStyle-Font-Bold="false" />

                                <telerik:GridBoundColumn DataField="EndDate" HeaderText="EndDate" SortExpression="EndDate" UniqueName="EndDate" DataType="System.DateTime" DataFormatString="{0:M/d/yyyy}" HeaderStyle-Font-Bold="true" ItemStyle-Font-Bold="false" />

                                <telerik:GridEditCommandColumn ButtonType="LinkButton" UniqueName="EditCommandColumn" />

                                <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="LinkButton" UniqueName="DeleteCommandColumn" ConfirmText="Delete Row?" ConfirmTitle="Delete?" />

                            </Columns>

                            

                        </MasterTableView>
                        <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="True">
                            <Selecting AllowRowSelect="True"></Selecting>
                        </ClientSettings>
                        <GroupingSettings ShowUnGroupButton="true" />
                    </telerik:RadGrid>

                    <div>
                        <br />
                        <table>
                            <tr>
                                <td>Upload Document:</td>
                                <td>
                                    <asp:FileUpload ID="FileUploadJquery" runat="server" multiple="multiple" class="multi" ClientIdMode="Static" title="Browse" TabIndex="25" onchange="UploadEducationFiles();" /></td>
                                <td>
                                    <asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" /></td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    <p id="demo"></p>
                                </td>
                            </tr>
                        </table>
                    </div>

                </telerik:RadAjaxPanel>

    I also tried to enable Autopostback on row selection but that did not help. 

    Can you please suggest me why is this happening. I am struggling from hours now. 

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 12 May Link to this post

    Hi Manav,

    The Ajax should not affect the behavior in this case. The values should be retrieved with and without AJAX.

    With that said, I tried to reproduce the behavior and the DataKeyValues were retrieved as expected on my end. I am attaching a sample project I used for testing. Give it a try and see how it works for you.

    I would appreciate if you can describe what should be different in the sample in order to replicate the problematic behavior.

    Regards,
    Viktor Tachev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Manav
    Manav avatar
    3 posts
    Member since:
    Apr 2016

    Posted 12 May in reply to Viktor Tachev Link to this post

    Hi Viktor

     

    Thanks for replying and the code sample. I have solved the issue. Apparently it was happening due to view state option for page in Sitefinity not being checked. It started working as soon as I checked that. 

     

  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 17 May Link to this post

    Hi Manav,

    I am glad that you were able to find the root cause of the issue. Thank you for sharing the solution with the community. This can help someone facing similar behavior.

    Regards,
    Viktor Tachev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top