[問題] GridView的ButtonField

看板C_Sharp (C#)作者 (眼睛茫然中)時間11年前 (2014/02/24 23:26), 編輯推噓0(003)
留言3則, 1人參與, 最新討論串1/2 (看更多)
不好意思又要打擾各位了。 目前我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)

02/24 23:42, , 1F
Gv.Row[x].Cell[y].Text = "<a href='' target='_new'>";
02/24 23:42, 1F

02/24 23:51, , 2F
用一般的欄位,直接把html弄上去就好,省PostBack的資源
02/24 23:51, 2F
感謝您的回答,但我直接把text的值用您的那一串程式碼指定,他就只是把那串文字 顯示出來而已,而不會是超連結。還是是因為用asp.net的關係?? ※ 編輯: coldwind7810 來自: 114.41.41.127 (02/25 00:52)

02/25 09:11, , 3F
<a href='http://xxx' target='_new'>Google This</a>
02/25 09:11, 3F
不好意思,可能是我基礎不夠,還是沒辦法試出來。 您的意思是整串程式碼寫成 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)
文章代碼(AID): #1J2sIGZL (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1J2sIGZL (C_Sharp)