Frage

I have a grid which has the CarrierID specified as the "DataKeyNames" which is also an invisible property in the grid.

I have a hyperlink column that when clicked should pass the value of the CarrierNetID (the keyvalue for that dataitem) into my codebehind so I can then pass it to another page to bring up a record for editing based on that key value.

I'm having trouble getting the attached error:

My markup is as follows: You can see that the lnkPLMN is the hyperlink. Everything is coming out on the grid just fine, I just can't seem to pass the value.

<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>

Here is my codebehind which gets the attached error on the following line: 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;
    }
}

Can someone please help?

After placing the hyperlink in the markup (instead of the code behind), I'm getting the following compilation error:

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

The Hyperlink column looks as follows:

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

What am I missing here?

War es hilfreich?

Lösung

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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top