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