看板 C_Sharp 關於我們 聯絡資訊
※ 引述《qweqweqweqwe (啪)》之銘言: (恕刪) : Button b; : for (int i = 0; i < GridView1.Rows.Count; i++) : { : if (GridView1.Rows[i].Cells[1].Text != "1") : { : b = (Button)GridView1.Rows[i].Cells[2].FindControl("Button1"); : b.Visible = false; : } : } : 假設我的表是長 : a 1 [button] : b 2 [button] : c 3 [button] : d 4 [button] : 這樣一來就只有 a 1 的button會顯示.. : aspx那邊就拉一個gridview 然後設定2個資料行 跟一個樣板 : 然後item裡面拉一個 button1就好了 : 這樣行嗎@@ 不好意思…因為我現在又出現一個問題! 以下是我的程式 if (session1 == accounts)//比對session是否為原發表人 { dr.Close(); //找該文章的回應 cmd = new SqlCommand("SELECT * FROM [replys] WHERE articles_id = '" + get_id + "'", cn); dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["reply_context"]=Server.HtmlDecode(dt.Rows[i]["reply_context"] .ToString().Replace("<br>", "\n")); } GridView2.DataSource = dt; GridView2.DataBind(); for (int j = 0; j < GridView2.Rows.Count; j++) { String re_account = GridView2.Rows[j].Cells[0].Text;//有問題 if (session1 == GridView2.Rows[j].Cells[0].Text) { GridView2.Columns[2].Visible = true; b=(LinkButton)GridView2.Rows[j].Cells[2].FindControl("LinkButton1"); b.Visible = true; } edit.Visible = true; } } 有問題的那行 GridView2.Rows[j].Cells[0].Text; ←抓不到 我有用Response.Write去試!裡面改成j或是"123"的時候值都出的來! 可是用Response.Write[re_account]值就出不來!完全抓不到! 可是我確定GridView2.Rows[1].Cells[0]是確實有資料! 想請問一下囧!有沒有人可以和我說這是什麼狀況阿?是傳說中的鬼打牆嗎?! -- 內有稀有動物 - 粉紅豬,請勿拍打餵食! http://blog.webs-tv.net/user/amy32340204.html -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.131.12.26 ※ 編輯: bigmommom 來自: 140.131.12.26 (10/16 20:11) ※ 編輯: bigmommom 來自: 140.131.12.26 (10/16 20:13) ※ 編輯: bigmommom 來自: 140.131.12.26 (10/16 20:13)