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

How to get DataKeyValue from RadGrid

1 Answer 521 Views
Grid
This is a migrated thread and some comments may be shown as answers.
loc pham
Top achievements
Rank 1
loc pham asked on 04 May 2010, 03:19 PM
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" AllowSorting="true" 
    ForeColor="White" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" 
    OnPreRender="RadGrid1_PreRender" PageSize="6" ShowHeader="False" Skin="Black"
    <ClientSettings >  
        <Selecting  AllowRowSelect="true" />  
    </ClientSettings> 
    <MasterTableView TableLayout="Fixed" DataKeyNames="ProductsId"
        <ItemTemplate> 
            <%# (((GridItem)Container).ItemIndex != 0)? "</td></tr></table>" : "" %> 
            <asp:Panel ID="ItemContainer" runat="server" CssClass='<%# (((GridItem)Container).ItemType == GridItemType.Item)? "item" : "alternatingItem" %>'
                <%# Eval("Title")%> 
                <br /> 
                <%# GetDescription(Eval("Description").ToString())%> 
                <br /> 
                <%#Eval("Price") %> 
                <br /> 
                <br /> 
                <br /> 
                <br /> 
                <asp:Button ID="btnReadmore" runat="server" Text="view details" OnClick="btnReadmore_Click" /> 
            </asp:Panel> 
        </ItemTemplate> 
    </MasterTableView> 
    <GroupingSettings CaseSensitive="False" /> 
    <HeaderContextMenu EnableAutoScroll="True"
    </HeaderContextMenu> 
    <PagerStyle Mode="NextPrev" /> 
</telerik:RadGrid>

And 

protected void btnReadmore_Click(object sender, EventArgs e)
    {
            ??? Code get Datakey Values
    }
 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 04 May 2010, 09:42 PM
Hello Loc,

Please try this approach:
protected void btnReadmore_Click(object sender, EventArgs e)
{
    GridDataItem item = (sender as Button).NamingContainer as GridDataItem;
    string myId = item.GetDataKeyValue("ProductsId").ToString();
}

Kind regards,
Daniel
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
loc pham
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or