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

DataKeyValues count = 0

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 05 Jun 2012, 08:00 PM
Hi,

I am trying to delete a row with the same code in the Telerik code sample, but my DataKeyValues is always empty.

Here is my code:

<telerik:RadGrid ID="gridNouvOrdo" runat="server" CellSpacing="0" GridLines="None">
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
    <ClientSettings>
        <Selecting CellSelectionMode="None"></Selecting>
    </ClientSettings>
    <MasterTableView CommandItemDisplay="Top">
        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column"
                ButtonType="ImageButton" EditText="Modifier" Resizable="False" HeaderStyle-Width="46px"
                EditImageUrl="Images/Icons/006-Write-New-Icon.png">
                <HeaderStyle Width="32px"></HeaderStyle>
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn CommandName="Delete" ConfirmText="Êtes-vous sûr de vouloir supprimer?"
                FilterControlAltText="Filter column column" Text="Supprimer" UniqueName="colDelete"
                ButtonType="ImageButton" ImageUrl="Images/Icons/059-Close-Delete-circle-Icon.png"
                ConfirmDialogType="Classic">
                <HeaderStyle Width="32px"></HeaderStyle>
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter colMedicament column" HeaderText="Médicament"
                UniqueName="colMedicament" DataField="NomMedicament">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter colPoso1 column" HeaderText="Posologie 1"
                UniqueName="colPoso1" DataField="Posologie">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter colPoso2 column" HeaderText="Posologie 2"
                UniqueName="colPoso2" DataField="Posologie2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter colQte column" HeaderText="Qté."
                UniqueName="colQte" ShowFilterIcon="false" DataField="Quantite">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter colRen column" HeaderText="Ren."
                UniqueName="colRen" ShowFilterIcon="false" DataField="Renouvellements">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter colComment column" HeaderText="Commentaire"
                UniqueName="colComment" DataField="Commentaire">
            </telerik:GridBoundColumn>
        </Columns>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

Protected Sub gridNouvOrdo_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles GridNouvOrdo.NeedDataSource
        gridNouvOrdo.DataSource = CurrentPropsBCM.OrdosManuelles
End Sub
 
Protected Sub gridNouvOrdo_DeleteCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles GridNouvOrdo.DeleteCommand
    Dim id = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)
 
End Sub

My DeleteCommand event currently do nothing, because it fail on the single line with a IndexOutOfBound.

Am I missing something? Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jun 2012, 04:23 AM
Hello Jocelyn,

Try setting the DataKeyNames for MasterTableView  and access it as shown below.
aspx:
<MasterTableView  DataKeyNames="EmployeeID" >
VB:
Private Sub RadGrid1_DeleteCommand(sender As Object, e As GridCommandEventArgs)
    Dim id As Object = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("EmployeeID")
End Sub

Thanks,
Shinu.
Tags
Grid
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or