問題描述
修改 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 loyalflow、Ruchi、CoderRoller)