我使用for循环使用VB.Net将列添加到DevExpress ASP.Net WebForms GridView。我能够获得一个超链接来引用相同的列值:
Dim newColumn As New DevExpress.Web.GridViewDataHyperLinkColumn
newColumn.PropertiesHyperLinkEdit.NavigateUrlFormatString = "TrendView.aspx?CurrentID={0}"
我需要以编程方式将超链接设置为另一列的值...即,第三列需要具有引用同一行中的列1值的超链接。如何在运行时使用VB或C#访问该行中的另一列?
答案 0 :(得分:1)
请参阅此网址以解决您的问题
https://www.devexpress.com/Support/Center/Example/Details/E308
将填充网格逻辑更改为
ASPX:
<dx:ASPxGridView ID="ASPxGridView1" runat="server"></dx:ASPxGridView>
<强> CS 强>
protected void Page_Init(object sender, EventArgs e)
{
ASPxGridView1.KeyFieldName = "ID";
ASPxGridView1.DataSource = GetData();
if (!IsPostBack && !IsCallback)
{
PopulateColumns();
ASPxGridView1.DataBind();
}
}
public DataTable GetData()
{
DataTable Table = new DataTable();
Table.Columns.Add("ID", typeof(int));
Table.Columns.Add("ItemName", typeof(string));
Table.Columns.Add("ItemValue", typeof(string));
Table.Rows.Add(1, "A","AA");
Table.Rows.Add(2, "B","BB");
return Table;
}
public void PopulateColumns()
{
GridViewDataTextColumn colID = new GridViewDataTextColumn();
colID.FieldName = "ID";
ASPxGridView1.Columns.Add(colID);
GridViewDataTextColumn srk = new GridViewDataTextColumn();
srk.FieldName = "ItemValue";
ASPxGridView1.Columns.Add(srk);
GridViewDataHyperLinkColumn colItemName = new GridViewDataHyperLinkColumn();
colItemName.FieldName = "ItemValue";
colItemName.PropertiesHyperLinkEdit.NavigateUrlFormatString = "~/details.aspx?Device={0}";
colItemName.PropertiesHyperLinkEdit.TextFormatString = "{0}";
colItemName.PropertiesHyperLinkEdit.TextField = "ItemName";
ASPxGridView1.Columns.Add(colItemName);
}
此处列itemName将itemValue称为url string params
答案 1 :(得分:0)
如果要基于多列显示超链接文本,则HyperlinkColumn不是正确的实现方法。最好使用模板。
您应该为列创建DataItemTemplate
,然后您可以使用Bind
语句格式化显示文本或超链接网址。它与ASP.NET GridView控件中使用的方法相同,并且与ASPxGridView控件的工作方式类似。
我建议您通过这些示例,附加的示例项目将帮助您了解实施情况。
ASPxGridView - How to customize HyperLink column
How to use a hyperlink whose argument depends on several cell values in the ASPxGridView
How to customize navigate URL for HyperLink column within a ASPxGridView - 这包含答案中附带的样本。
示例:列的DataItemTemplate。
<dxwgv:GridViewDataTextColumn FieldName="ContactName" VisibleIndex="3">
<DataItemTemplate>
<dxe:ASPxComboBox ID="ASPxComboBox1" runat="server" ValueType="System.String" DataSourceID="AccessDataSource1"
TextField="ContactName" ValueField="ContactName" Value='<%#Bind("ContactName")%>' OnSelectedIndexChanged="ASPxComboBox1_SelectedIndexChanged">
<ClientSideEvents SelectedIndexChanged="onSelectedIndexChanged" />
</dxe:ASPxComboBox>
</DataItemTemplate>
</dxwgv:GridViewDataTextColumn>
或
<dx:ASPxHyperLink ID="ASPxHyperLink3" runat="server"
NavigateUrl='<%# string.Format("~/AccountDetail.aspx?CategoryID={0}", Eval("i_Customer")) %>'
Text='<%# string.Format("i_Customer{0}", Eval("i_Customer")) %>' .../>
ASPxGridView - ASPxHyperLink Navigate URL formatting
ASPxGridView - How to set GridViewDataHyperlinkColumn's text and navigate url