Current filter:
                                You should refresh the page.
                                Support Center

                                How to use a hyperlink whose argument depends on several cell values in the ASPxGridView

                                0

                                It is an often situation when a developer should include sever field values in a hyperlink shown in a GridView column cells. The best solution to this problem is to use templates. The attached example shows how this can be done and suggests two similar approaches:

                                1) in the "simple" case the href parameter of the <a> element is defined by the KeyValue of the processed row
                                2) in the "complex" case, the href parameter of the <a> element is defined in the server side GetRowValue method.

                                • smoore4 12.17.2013

                                  This also works. Use a Command Column (eg Custom Button) and code it like this:

                                          protected void ASPxGridView1_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
                                          {

                                              if (e.ButtonID == "cmdOpenSurveyRpt")
                                              {

                                                  object[] m_rptvars = (object[])ASPxGridView1.GetRowValues(e.VisibleIndex, "survey_id", "survey_user_id");

                                                  ASPxWebControl.RedirectOnCallback("~/Reports/ReportViewer.aspx" + "?sid=" + m_rptvars[0] + "&uid=" + m_rptvars[1]);

                                              }

                                          }

                                You must  log in  or  register  to leave comments
                                Select file
                                • Default.aspx
                                • Default.aspx.cs
                                • Default2.aspx
                                • Default2.aspx.cs
                                • TestGridViewSite81
                                Select language
                                • C#
                                • VB.NET
                                Select version
                                • v2013 vol 1.4 - v2013 vol 2.9
                                • v2008 vol 1.8 - v2012 vol 2.16
                                <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"  MasterPageFile="~/MasterPage.master"%>
                                
                                <%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.1, Version=8.1.8.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
                                    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
                                
                                <%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.1, Version=8.1.8.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
                                    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
                                    
                                <asp:Content ContentPlaceHolderID="ContentPlaceHolder1" ID="CC" runat="Server">
                                    <dxwgv:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="AccessDataSource2" KeyFieldName="CategoryID" PreviewFieldName="Notes" AutoGenerateColumns="False" EnableRowsCache="False" OnRowUpdating="grid_RowUpdating">
                                        <SettingsBehavior AllowFocusedRow="True" ConfirmDelete="True"/>
                                        <Settings  ShowGroupPanel="True" />
                                        <Columns>
                                            <dxwgv:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
                                                <EditFormSettings Visible="False" />
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn VisibleIndex="3" Caption="Simple Hyperlink Column">
                                                <DataItemTemplate>
                                                    <a id="clickElement" target="_blank" href="Default2.aspx?id=<%# Container.KeyValue%>"><%# "Show New Form, Key Field = " + Eval("CategoryID").ToString()%></a>
                                                </DataItemTemplate>
                                            </dxwgv:GridViewDataTextColumn>
                                            <dxwgv:GridViewDataTextColumn VisibleIndex="4" Caption="Complex Hyperlink Column">
                                                <DataItemTemplate>
                                                    <a id="clickElement" target="_blank" href="Default2.aspx?id=<%# GetRowValue(Container)%>"><%# "Show New Form, CategoryName = " + Eval("CategoryName").ToString()%></a>
                                                </DataItemTemplate>
                                            </dxwgv:GridViewDataTextColumn>
                                        </Columns>
                                    </dxwgv:ASPxGridView>
                                        <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/nwind.mdb"
                                        SelectCommand="SELECT * FROM [Categories]">
                                    </asp:AccessDataSource>
                                </asp:Content>

                                To start a chat you should create a support ticket


                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners