ASPXGridview中的超链接

时间:2014-01-13 10:07:57

标签: c# javascript asp.net devexpress aspxgridview

我想在“目标”列中为每个值添加超链接。因此,如果您点击“目标”列中的任何值,那么它将转到另一个页面。

我希望将此页面链接到该页面:'included_codes.aspx'

要进入此页面,您需要传递dr_id,它是每行中的值。它没有显示在网格上,但它仍然存在于数据源中。

我需要知道如何对此进行编码,以便可以点击“目标”列中的每个值,它将转到includes_codes.aspx页面。

这是网格的代码:

<dxwgv:ASPxGridView ID="dgrdResults" runat="server" AutoGenerateColumns="False" 
                DataSourceID="DedicatedRouteDataSource" Width="100%" 
                onhtmlrowcreated="dgrdResults_HtmlRowCreated">
                <Columns>
                    <dxwgv:GridViewDataTextColumn Caption="Switch" FieldName="switch_code" 
                        VisibleIndex="0" Width="30px">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="LCR" FieldName="lcr_name" 
                        VisibleIndex="1">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Customer" FieldName="cus_company_name" 
                        VisibleIndex="2" Width="150px">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Vendor" FieldName="carrier" 
                        VisibleIndex="3">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Ratio" 
                        VisibleIndex="4">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Overflow" 
                        VisibleIndex="5">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Destination" FieldName="bnd_name" 
                        VisibleIndex="6">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Peak" FieldName="peak" 
                        VisibleIndex="7">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="O/Peak" FieldName="off_peak" 
                        VisibleIndex="8">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="W/End" FieldName="weekend" 
                        VisibleIndex="9">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Created" FieldName="active_date" 
                        VisibleIndex="10">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Status" FieldName="stt_display_order" 
                        VisibleIndex="11">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Special" VisibleIndex="12">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Comments" FieldName="comments" 
                        VisibleIndex="13">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Edit" VisibleIndex="14">
                    </dxwgv:GridViewDataTextColumn>
                </Columns>
                <SettingsPager PageSize="16" ></SettingsPager>                                                       
            </dxwgv:ASPxGridView>

2 个答案:

答案 0 :(得分:1)

找到答案:

        if (e.RowType == GridViewRowType.Data)
        {              
            ASPxGridView dgrdResults = sender as ASPxGridView;
            ASPxHyperLink destinationLink = dgrdResults.FindRowCellTemplateControl(e.VisibleIndex, null, "DestinationLink") as ASPxHyperLink;
            ASPxHyperLink statusLink = dgrdResults.FindRowCellTemplateControl(e.VisibleIndex, null, "stt_display_order") as ASPxHyperLink;

            if (e.GetValue("bnd_name") != null)
            {
                int DrId = Convert.ToInt32((e.GetValue("dr_id")));
                destinationLink.NavigateUrl = "./included_codes.aspx?mode=Edit&dr_id=" + DrId;
            }
            else
            {
                destinationLink.Enabled = false;
                destinationLink.ForeColor = Color.Black;
            }

        }

答案 1 :(得分:0)

添加此代码并尝试

 <dxwgv:GridViewDataTextColumn VisibleIndex="3" Caption="Simple Hyperlink Column">
            <DataItemTemplate>
                <a id="clickElement" target="_blank"   
                href='included_codes.aspx.aspx?dr_id=<%# Container.KeyValue%>"><%# "Show New Form, Key Field = " + Eval("YourFieldName").ToString()%></a>
            </DataItemTemplate>
 </dxwgv:GridViewDataTextColumn>

有关详细信息,请参阅this链接!