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.