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

RadGrid Losing Row Selection on postback

3 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manav
Top achievements
Rank 1
Manav asked on 10 May 2016, 01:28 PM

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. 

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 12 May 2016, 12:52 PM
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.
0
Manav
Top achievements
Rank 1
answered on 12 May 2016, 06:20 PM

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. 

 

0
Viktor Tachev
Telerik team
answered on 17 May 2016, 12:41 PM
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.
Tags
Grid
Asked by
Manav
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Manav
Top achievements
Rank 1
Share this question
or