写了一个GridView_RowUpdating事件,想把GridView中单元格中的值读出来存入全局变量的数组,但是,好像出了这个事件,对全局变量的修改就无效了,全局变量的值又恢复了初始值。查了下,原来C#中好像没有全局变量,于是按照2002年的帖子改成了类的形式,
public class globevar
{
static float[,] nulcols423 = new float[2, 3];
static float[,] nulcols827 = new float[2, 7];
static float[,] nulcols934 = new float[3, 4];
} protected void Button1_Click(object sender, EventArgs e)
{
foreach (float var in globevar.nulcols423)
{
Response.Write(var.ToString() + "---->");
}
}
提示,“受保护级别限制不可访问”求高手,指点啊。本人基础较差,又急于交毕设,水平十分有限请见谅啊。protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
switch (Label1.Text.ToString())
{
case "ippt423":
int number = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString().Substring(5, 1));
switch (number)
{
case 1:
for (int i = 2; i < 5; i++)
{ nulcols423[0, i - 2] = float.Parse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[i].Controls[0])).Text.ToString().Trim()); }
break;
case 2:
for (int j = 2; j < 5; j++)
{ nulcols423[1, j - 2] = float.Parse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[j].Controls[0])).Text.ToString().Trim()); }
break;
}
GridView1.EditIndex = -1;
newbind(Label1.Text.ToString());
foreach (float var in nulcols423)
{
Response.Write(var.ToString() + "<======>");
}
break;
public class globevar
{
static float[,] nulcols423 = new float[2, 3];
static float[,] nulcols827 = new float[2, 7];
static float[,] nulcols934 = new float[3, 4];
} protected void Button1_Click(object sender, EventArgs e)
{
foreach (float var in globevar.nulcols423)
{
Response.Write(var.ToString() + "---->");
}
}
提示,“受保护级别限制不可访问”求高手,指点啊。本人基础较差,又急于交毕设,水平十分有限请见谅啊。protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
switch (Label1.Text.ToString())
{
case "ippt423":
int number = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString().Substring(5, 1));
switch (number)
{
case 1:
for (int i = 2; i < 5; i++)
{ nulcols423[0, i - 2] = float.Parse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[i].Controls[0])).Text.ToString().Trim()); }
break;
case 2:
for (int j = 2; j < 5; j++)
{ nulcols423[1, j - 2] = float.Parse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[j].Controls[0])).Text.ToString().Trim()); }
break;
}
GridView1.EditIndex = -1;
newbind(Label1.Text.ToString());
foreach (float var in nulcols423)
{
Response.Write(var.ToString() + "<======>");
}
break;
敢情你那个nulcols423的访问权限修饰符比protected还低
{
public static float[,] nulcols423 = new float[2, 3];
public static float[,] nulcols827 = new float[2, 7];
public static float[,] nulcols934 = new float[3, 4];
}
开始,不知道为什么写public static出错,删除全部,重新写一遍又不知道为什么就对了....我想全局变量,访问级别应该比较开放吧。反正先调试通了再考虑安全性什么的,呵呵...
public static float[,] nulcols827 = new float[2, 7];
public static float[,] nulcols934 = new float[3, 4];这样写完全没问题或者只要在方法外 类里面 那么作用域就是整个类了。。你要看它的作用域