修改 aspxgrid 中的列以顯示超鏈接和支持組 (Modify column in aspxgrid to display a hyper link and support group by)


問題描述

修改 aspxgrid 中的列以顯示超鏈接和支持組 (Modify column in aspxgrid to display a hyper link and support group by)

I have a devexpress gridview that displays the UserID in a column. I group by this column, and I want to modify the value that is displayed by adding a hyperlink to point to the user profile page.

<dx:ASPxGridView ..>

<Columns>
..

<dx:GridViewDataColumn FieldName="UserID" Caption="User" VisibleIndex="2" 
  Visible="false">
  <Settings AllowSort="False" AllowDragDrop="False" />                                
</dx:GridViewDataColumn>

..
</Columns>

</dx:ASPxGridView>

But whenever I try to add a DataItemTemplate, it doesn't effect the output at all.

How can I modify what is displayed with a link?

Right now it shows:

User 12323

I want to display:

User <a href="/profile.aspx?userid=12323">12323</a>

參考解法

方法 1:

This code would show 12323 as a hyperlink which would take as ID and redirect to your desired page. 

       <dx:GridViewDataHyperLinkColumn VisibleIndex="0" Settings-FilterMode="DisplayText" Caption="User" 
                ShowInCustomizationForm="True"
             FieldName="UserID" Width="58px">
            <DataItemTemplate>
              <dx:ASPxHyperLink Font-Size="11px" ForeColor="Blue" ID="ASPxHyperLinkTest" Target="_blank" runat="server" Text='<%#Eval("UserID") %>'
 NavigateUrl='<%#string.Format("profile.aspx?userid={0}",Eval("UserID"))%>'>
        </dx:ASPxHyperLink>
      </DataItemTemplate>
    </dx:GridViewDataHyperLinkColumn>

方法 2:

I haven't used a DevExpress Gridview before but if it inherits from GridView then this could work:

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Cells(0).Text = "User <a href=""/profile.aspx?userid=" & DataBinder.Eval(e.Row.DataItem, "UserID") & """>" + DataBinder.Eval(e.Row.DataItem, "UserID") + "</a>"
        End If

End Sub

(by loyalflowRuchiCoderRoller)

參考文件

  1. Modify column in aspxgrid to display a hyper link and support group by (CC BY-SA 3.0/4.0)

#ASP.NET #devexpress #C#






相關問題

System.Reflection.Assembly.LoadFile 鎖定文件 (System.Reflection.Assembly.LoadFile Locks File)

如何在沒有全局變量的情況下一直保留我的變量? (How can I keep my variable all the time without global variables?)

C# / ASP.NET - Web 應用程序鎖定 (C# / ASP.NET - Web Application locking)

關閉模態對話框窗口後 ASP.NET 刷新父頁面 (ASP.NET Refresh Parent Page after Closing Modal Dialog Window)

無法將 NULL 值傳遞給數據庫 (Unable to pass NULL value to database)

wcf:將用戶名添加到消息頭是否安全? (wcf: adding username to the message header is this secure?)

使用 ASP.Net 教初學者 Web 開發的小項目想法 (Small projects ideas to teach beginners web development using ASP.Net)

SQL Server - 分組、擁有和計數 (SQL Server - Group by, having and count in a mix)

企業庫異常處理應用程序塊和日誌記錄應用程序塊在 ASP.NET 中的正確使用 (Enterprise Library Exception Handling Application Block and Logging Application Block proper use in ASP.NET)

來自proc的asp.net多個結果集:是否有必要將結果映射到類?如果是這樣,怎麼做? (asp.net multiple result set from proc: is it necessary to map results to class? If so, how?)

如何在測試工具中實例化 asp.net 代碼隱藏類? (How can I instantiate an asp.net codebehind class in a test harness?)

Web 窗體用戶控制事件,需要在頁面加載後添加 (Web Form User Control Event, needs to be added after page loads)







留言討論