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

how to retrieve one row data from a gridtemplatecolumn cell

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 01 May 2012, 04:33 PM
I’m creating a radgrid like this, I bound the data to first four columns, in the last column, I create a GridTemplateColumn, and want to do like this: when click “action”, it will generate a dropdown list let you to choose edit, delete or email. The question is, how can I achieve the row data(especially the quote ID) when clicking  the GridTemplateColumn cell, I can’t get it through, please help. Thank you!
I’m creating a radgrid like this, I bound the data to first four columns, in the last column, I create a GridTemplateColumn, and want to do like this: when click “action”, it will generate a dropdown list let you to choose edit, delete or email. The question is, how can I achieve the row data(especially the quote ID) when clicking  the GridTemplateColumn cell, I can’t get it through, please help. Thank you!

<
body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
         
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
 
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
        </telerik:RadAjaxLoadingPanel>
 
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"
            PageSize="26" Height="720px"
         AllowSorting="True" AllowPaging="True" AllowFilteringByColumn="True"
            Skin="Office2010Blue" CellSpacing="0" GridLines="None">
            <ClientSettings EnableRowHoverStyle="true">
                <Selecting CellSelectionMode="None" AllowRowSelect="true"></Selecting>
                <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="686px" />
                <ClientEvents OnRowMouseOver="quotes_DataGridRowMouseOverV2" OnRowSelected="quotes_DataGridFunction_V2"/>
                <Resizing AllowColumnResize="true" AllowResizeToFit="true" ResizeGridOnColumnResize="true" EnableRealTimeResize="true"/>
            </ClientSettings>
 
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" ClientDataKeyNames="ID,Bill_CompanyName"
                            DataSourceID="SqlDataSource1">
                <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:GridBoundColumn DataField="ID" DataType="System.Int32"
                        FilterControlAltText="Filter ID column" HeaderText="Quote #" ReadOnly="True"
                        SortExpression="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CreateDateTime" DataType="System.DateTime"
                        FilterControlAltText="Filter CreateDateTime column" HeaderText="Create Date&Time"
                        SortExpression="CreateDateTime" UniqueName="CreateDateTime">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Bill_CompanyName"
                        FilterControlAltText="Filter Bill_CompanyName column"
                        HeaderText="Customer Name" SortExpression="Bill_CompanyName"
                        UniqueName="Bill_CompanyName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="QuoteTotal"
                        FilterControlAltText="Filter QuoteTotal column"
                        HeaderText="Quote Total" SortExpression="QuoteTotal"
                        UniqueName="QuoteTotal">
                    </telerik:GridBoundColumn>
 
                    <telerik:GridTemplateColumn
                        HeaderText="Action" UniqueName="TemplateColumn" AllowFiltering="false">
                        <ItemTemplate>
                            <asp:HyperLink ID="HyperLink1" runat="server">Action</asp:HyperLink>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                     
                </Columns>
 
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
                </EditFormSettings>
            </MasterTableView>
 
            <FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="Data Source=192.168.1.92,32071;Initial Catalog=EZPricing2;Persist Security Info=True;User ID=tem;Password=sim32071#@)&!"
            ProviderName="System.Data.SqlClient"
             
            SelectCommand="SELECT ID, Bill_CompanyName, CreateDateTime, QuoteTotal FROM tb_Quote WHERE (SalesRepId = @SalesRepId)">
            <SelectParameters>
                <asp:Parameter DefaultValue="97" Name="SalesRepId" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
 
    </div>
    </form>
</body>





1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 May 2012, 06:43 AM
Hello Jason,

One suggestion is you can access the HyperLink from code behind and pass the DataKeyNames as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
   GridDataItem item = (GridDataItem)e.Item;
   string value=item.GetDataKeyValue("ID").ToString();
   HyperLink link = (HyperLink)item.FindControl("HyperLink1");
  link.NavigateUrl = "Page.aspx" + value;
  }
}

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