作者coldwind7810 (眼睛茫然中)
看板C_Sharp
标题[问题] GridView的ButtonField
时间Mon Feb 24 23:26:05 2014
不好意思又要打扰各位了。
目前我asp.net的程式码架构如下:
private void showResults(string[,] itemInformation, bool[] results)
{
DataTable dtRecommend = new DataTable("Item");
dtRecommend.Columns.Add(new DataColumn("标题", typeof(string)));
dtRecommend.Columns.Add(new DataColumn("摘要", typeof(string)));
dtRecommend.Columns.Add(new DataColumn("连结", typeof(string)));
DataRow row = dtRecommend.NewRow();
for (int i = 0; i < results.Length; i++)
{
if (results[i] == true)
{
row["标题"] = itemInformation[i,0];
row["摘要"] = itemInformation[i,1];
row["连结"] = itemInformation[i,2];
dtRecommend.Rows.Add(row);
}
}
GridView.DataSource = dtRecommend;
GridView.DataBind();
}
目前我的问题是我希望把"连结"那一栏用ButtonField取代,并把超连结的资料用新分页
的方式开启。
我有在GridView新增ButtonField的栏位,并设定好了CommandName,也有找到要判别
是否按到ButtonField并启动需要用到GridView_RowCommand这个事件。
但我该如何把我超连结的值塞到按钮中并触动事件开启新分页。
先感谢各位的帮忙了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.41.41.127
※ 编辑: coldwind7810 来自: 114.41.41.127 (02/24 23:28)
1F:→ m339606:Gv.Row[x].Cell[y].Text = "<a href='' target='_new'>"; 02/24 23:42
2F:→ m339606:用一般的栏位,直接把html弄上去就好,省PostBack的资源 02/24 23:51
感谢您的回答,但我直接把text的值用您的那一串程式码指定,他就只是把那串文字
显示出来而已,而不会是超连结。还是是因为用asp.net的关系??
※ 编辑: coldwind7810 来自: 114.41.41.127 (02/25 00:52)
3F:→ m339606:<a href='http://xxx' target='_new'>Google This</a> 02/25 09:11
不好意思,可能是我基础不够,还是没办法试出来。
您的意思是整串程式码写成
row["连结"] =
"<a href='
http://" + itemInformation[i, 2] + "'target='_new'>按钮名称</a>";
这样吗??
※ 编辑: coldwind7810 来自: 120.107.152.28 (02/25 11:52)
※ 编辑: coldwind7810 来自: 120.107.152.28 (02/25 11:58)