Re: [问题] GridView的ButtonField

楼主: m339606 (mize)   2014-02-25 12:34:16
※ 引述《coldwind7810 (眼睛茫然中)》之铭言:
: 不好意思又要打扰各位了。
: 目前我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这个事件。
: 但我该如何把我超连结的值塞到按钮中并触动事件开启新分页。
: 先感谢各位的帮忙了
你现在处理的方式是将资料处理成DataTable并指定给GridView
在这种状况下你将HTML格式直接丢入DataTable是没有用的,他会把你当文字处理
解决方法:
写入GridView的PreRender事件
参考程式码
http://pastie.org/8772940
其中string.Format语法请Google
GridView事件说明请参阅
http://ppt.cc/lb2O
延伸阅读:
页面事件顺序 http://www.dotblogs.com.tw/boei/archive/2010/07/10/16484.aspx
作者: coldwind7810   2014-02-25 19:13:00
原来如此,我再试试,感谢大大!!!感谢您,我试出来了!!!

Links booklink

Contact Us: admin [ a t ] ucptt.com