DataGrid的超链接问题? 急急!!

jin987 2004-06-10 11:44:07
DataGrid的超链接问题,现在超链接可以实现,问题是怎样使这一列的有条件的能实现超链接,也就是说,这一列有的字段可以超链接,而有的不能实现超链接。!!!!!!分不够可以狂加!!!
...全文
118 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2004-06-10
  • 打赏
  • 举报
回复
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<html>
<script runat="server">
int start_index;
ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(string)));

for (int i = start_index; i < start_index + ItemsGrid.PageSize; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = @"我是中文文字,";
dr[2] = DateTime.Now.ToString();;

dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

void Page_Load(Object sender, EventArgs e)
{
//对于没有数字的内容,下面这行完全满足要求,但加了数字就不行,必须调用OnItemDataBound
ItemsGrid.Attributes.Add("style","word-break:keep-all;word-wrap:normal");

//下面这行是自动换行
//ItemsGrid.Attributes.Add("style","word-break:break-all;word-wrap:break-word");

if (!IsPostBack)
{
BindGrid();
}
}

void BindGrid()
{
ItemsGrid.DataSource=CreateDataSource();
ItemsGrid.DataBind();
}

void Item_DataBound(Object sender, DataGridItemEventArgs e)
{
if( e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if(e.Item.ItemIndex % 2 == 0)
e.Item.Cells[1].Text = "<a href=''>" + e.Item.Cells[1].Text + "</a>";
else
e.Item.Cells[2].Text = "<nobr>" + e.Item.Cells[2].Text + "</nobr>";
}
}

</script>
<body>
<form runat="server">
<asp:DataGrid id="ItemsGrid" runat="server" BorderColor="black"
OnItemDataBound="Item_DataBound" AutoGenerateColumns="false">

<AlternatingItemStyle BackColor="#DEDEDE"></AlternatingItemStyle>
<HeaderStyle BackColor="#EEEEFF" HorizontalAlign="Center"></HeaderStyle>

<Columns>
<asp:BoundColumn HeaderText="序号" DataField="IntegerValue"/>
<asp:BoundColumn HeaderText="文字" DataField="StringValue"/>
<asp:BoundColumn HeaderText="价格" DataField="CurrencyValue" DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="right"></ItemStyle>
</asp:BoundColumn>
</Columns>

</asp:DataGrid>
</form>
</body>
</html>
liangshaojun 2004-06-10
  • 打赏
  • 举报
回复
先DataGrid加上一个超链接列

DataGrid_ItemDataBound事件中

if(条件)//不能超链接为true
{
e.Item.Cells[超链接列].Text = "不能超链接";
}
gabriel1 2004-06-10
  • 打赏
  • 举报
回复
当然用摸板列啊,昏倒。

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧