0

我有一个网格,它的 CarrierID 指定为“DataKeyNames”,这也是网格中的一个不可见属性。

我有一个超链接列,单击该列时应将 CarrierNetID 的值(该数据项的键值)传递到我的代码隐藏中,这样我就可以将其传递到另一个页面,以根据该键值调出一条记录进行编辑。

我无法收到附加的错误:

我的标记如下: 你可以看到 lnkPLMN 是超链接。一切都很好,我似乎无法传递价值。

<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" ShowStatusBar="true"
    runat="server" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True"
    AutoGenerateColumns="false" ClientSettings-Resizing-AllowColumnResize="true"
    DataKeyNames="CarrierNetID" OnItemDataBound="RadGrid_ItemDataBound">

    <MasterTableView PageSize="10" Width="100%">
        <Columns>
            <telerik:GridBoundColumn DataField="CarrierNetID" Visible="false" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Carrier Name" UniqueName="Name" SortExpression="Name" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Region" HeaderText="Region" UniqueName="Region" AllowFiltering="true" SortExpression="Region" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Country" HeaderText="Country" UniqueName="Country" SortExpression="Country" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="PLMN" UniqueName="PLMN">
                <ItemTemplate>
                    <asp:HyperLink ID="lnkPLMN" runat="server" Target="_blank" ForeColor="Blue">
                    </asp:HyperLink>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="TechnologyTypeCode" HeaderText="Technology" UniqueName="TechnologyTypeCode" SortExpression="TechnologyTypeCode" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="SMSMORate" HeaderText="SSMSO Rate" UniqueName="SMSMORate" AllowFiltering="false" SortExpression="SMSMORate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="SMSMTRate" HeaderText="SMSMT Rate" UniqueName="SMSMTRate" AllowFiltering="false" SortExpression="SMSMTRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DataRate" HeaderText="Data Rate" UniqueName="DataRate" AllowFiltering="false" SortExpression="DataRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="MOCRate" HeaderText="MOC Rate" UniqueName="MOCRate" AllowFiltering="false" SortExpression="MOCRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="MTCRate" HeaderText="MTC Rate" UniqueName="MTCRate" AllowFiltering="false" SortExpression="MTCRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField="FlatRate" HeaderText="Flat Rate" UniqueName="FlatRate" SortExpression="FlatRate" ReadOnly="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn DataField="Discount" HeaderText="Discount" UniqueName="Discount" SortExpression="Discount" ReadOnly="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn DataField="ActiveFlag" HeaderText="Active" UniqueName="ActiveFlag" SortExpression="ActiveFlag" ReadOnly="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings EnableRowHoverStyle="true">
    </ClientSettings>
    <PagerStyle Mode="NumericPages"></PagerStyle>
</telerik:RadGrid>

这是我的代码隐藏,它在以下行中获取附加错误: HyperLink link = (HyperLink)item["PLMN"].Controls[0];

protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        HyperLink link = (HyperLink)item["PLMN"].Controls[0];
        string value = item.GetDataKeyValue("CarrierNetID").ToString();
        link.NavigateUrl = "~/CarrierLaunchStatusForm.aspx?addRecord=0&ID=" + value;
    }
}

有人可以帮忙吗?

将超链接放在标记中(而不是后面的代码)后,我收到以下编译错误:

Error   2   The GridHyperLinkColumn control with a two-way databinding to field PLMN must have an ID.   C:\Projects\NPP\NPP\NPP\NPP\CarrierLaunchStatus.ascx    53
Error   3   Literal content ('</telerik:GridHyperLinkColumn>') is not allowed within a 'Telerik.Web.UI.GridColumnCollection'.   C:\Projects\NPP\NPP\NPP\NPP\CarrierLaunchStatus.ascx    56

超链接列如下所示:

<telerik:GridHyperLinkColumn UniqueName="PLMN" DataTextFormatString='<%# Bind("PLMN") %>'
                    DataTextField="PLMN" DataNavigateUrlFields="CarrierNetID" DataNavigateUrlFormatString="~/CarrierLaunchStatusForm.aspx?addRecord=0&ID={0}"
                    Target="_blank">
                </telerik:GridHyperLinkColumn>

我在这里想念什么?

4

1 回答 1

1

Unless you really need to modify data on the ItemDataBound event, You can just use the GridHyperLinkColumn:

<telerik:GridHyperLinkColumn DataNavigateUrlFields="CarrierNetID"
    DataNavigateUrlFormatString="~/CarrierLaunchStatusForm.aspx?addRecord=0&ID={0}"
    Target="_blank" Text="Your Link Text"></telerik:GridHyperLinkColumn>
于 2013-03-14T00:06:19.010 回答