作者bigmommom (程式追追追…问题一大堆)
看板C_Sharp
标题Re: [问题]GridView的编辑
时间Tue Oct 16 20:10:05 2007
※ 引述《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)