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

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

1 Answer 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vuyiswa
Top achievements
Rank 2
Vuyiswa asked on 31 Jan 2010, 09:13 PM
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">  
                        <MasterTableView> 
                        <RowIndicatorColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                        </RowIndicatorColumn> 
                        <Columns> 
                        <telerik:GridTemplateColumn DataField="CategoryID" HeaderText="ID" UniqueName="TemplateColumn">  
                        <ItemTemplate> 
                        <asp:Label ID="lblID" Font-Bold="true" runat="server" Text='<%# Eval("CategoryID")%>' ></asp:Label> 
                        </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn HeaderText="Forum Categories" UniqueName="TemplateColumn1">  
                        <ItemTemplate> 
                        <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> 
                        </telerik:GridTemplateColumn> 
                        </Columns> 
                        <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                        </ExpandCollapseColumn> 
                        </MasterTableView> 
                        <FilterMenu EnableTheming="True" Skin="Sunset">  
                        <CollapseAnimation Type="OutQuint" Duration="200">  
                        </CollapseAnimation> 
                        </FilterMenu> 
    <ClientSettings> 
        <ClientEvents OnRowClick="OnClientClick=&quot;javascript: return SetHidSelectedRows()&quot;" /> 
    </ClientSettings> 
    </telerik:RadGrid> 
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.

Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 01 Feb 2010, 05:20 AM
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.

CS:
 
    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,
Shinu.
Tags
Grid
Asked by
Vuyiswa
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 1
Share this question
or