How to Get the ID of a Hidden Field in a grid

2 posts, 0 answers
  1. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 31 Jan 2010 Link to this post

    Good Day All

    i have a Radgrid defined like this

    <telerik:RadGrid ID="RagCategories" runat="server" Height="399px" Width="698px" AutoGenerateColumns="False" Skin="Sunset" OnDataBound="RagCategories_DataBound">  
                            <HeaderStyle Width="20px"></HeaderStyle> 
                            <telerik:GridTemplateColumn DataField="CategoryID" HeaderText="ID" UniqueName="TemplateColumn">  
                            <asp:Label ID="lblID" Font-Bold="true" runat="server" Text='<%# Eval("CategoryID")%>' ></asp:Label> 
                            <telerik:GridTemplateColumn HeaderText="Forum Categories" UniqueName="TemplateColumn1">  
                            <asp:HyperLink id="link1" Text='<%# Eval("CATEGORYNAME")%>'  NavigateUrl='<%# Eval("[LINK]")%>' runat="server" > </asp:HyperLink> 
                            <asp:Label ID="descr" runat="server" Text='<%# Eval("Description")%>'></asp:Label> 
                            </ItemTemplate><HeaderStyle Font-Bold="True">  
                            <HeaderStyle Width="20px"></HeaderStyle> 
                            <FilterMenu EnableTheming="True" Skin="Sunset">  
                            <CollapseAnimation Type="OutQuint" Duration="200">  
            <ClientEvents OnRowClick="OnClientClick=&quot;javascript: return SetHidSelectedRows()&quot;" /> 
    in this Grid there is "CategoryID" and on RowDatabound event i hide this Column and it working. now in this Grid i have this

    <asp:HyperLink id="link1" Text='<%# Eval("CATEGORYNAME")%>'  NavigateUrl='<%# Eval("[LINK]")%>' runat="server" > 
    as shown above,when my user clicks the Hyperlink in the Grid, this will take the user to the Appropriate Page,its Good , and i want to save the "CategoryID" of the selected Hyperlink. Am open to suggestion, i
    can still use the Button link and onclick and get the Category_id of the selected button list. Please note that in this grid there wont be any multi select.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 Jan 2010 Link to this post

    Hi Vuyiswa,

    You can pass the corresponding CategoryID of clicked row as url parameter. Then access the value in the new page. The following code shows how to add the url parameter to HyperLink placed in ItemTemplate.

        protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
            if (e.Item is GridDataItem) 
                GridDataItem item = (GridDataItem)e.Item; 
                HyperLink hLink = (HyperLink)item.FindControl("link1"); 
                hLink.NavigateUrl = hLink.NavigateUrl + "?categoryID=" + item.GetDataKeyValue("CategoryID"); 

    Also set the DataKeyNames as CategoryID in order to use the GetDataKeyValue() method.
             <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="CategoryID">

    Hope this helps,
  3. DevCraft R3 2016 release webinar banner
Back to Top