我在页面上有一个label2,我想让pv的值显示在label2上,不知道哪里有问题 protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{ int cs,pv;
cs = System.Convert.ToInt32(xinxi("cishu"));
if (cs == 1)
{
pv = 13;
}
else
{
if (cs == 2)
{
pv =27;
}
else
{
if (cs == 3)
{
pv = 80;
}
else
{
if (cs == 4)
{
pv = 100;
}
else
{
if (cs == 5)
{
pv = 135;
}
else
{
if (cs == 6)
{
pv = 160;
}
else
{
if (cs == 7)
{
pv = 120;
}
else
{
if (cs == 8)
{
pv = 320;
}
else
{
if (cs == 9)
{
pv = 640;
}
else
{
if (cs == 10)
{
pv = 1280;
}
else
{
if (cs == 11)
{
pv = 2560;
}
}
}
} }
}
}
}
}
}
}
return pv;
this.Label1.Text = xinxi("cishu");
this.Label2.Text ="+pv+";
{
if (!Page.IsPostBack)
{ int cs,pv;
cs = System.Convert.ToInt32(xinxi("cishu"));
if (cs == 1)
{
pv = 13;
}
else
{
if (cs == 2)
{
pv =27;
}
else
{
if (cs == 3)
{
pv = 80;
}
else
{
if (cs == 4)
{
pv = 100;
}
else
{
if (cs == 5)
{
pv = 135;
}
else
{
if (cs == 6)
{
pv = 160;
}
else
{
if (cs == 7)
{
pv = 120;
}
else
{
if (cs == 8)
{
pv = 320;
}
else
{
if (cs == 9)
{
pv = 640;
}
else
{
if (cs == 10)
{
pv = 1280;
}
else
{
if (cs == 11)
{
pv = 2560;
}
}
}
} }
}
}
}
}
}
}
return pv;
this.Label1.Text = xinxi("cishu");
this.Label2.Text ="+pv+";
报错为 CS0165: 使用了未赋值的局部变量“pv”
cs = System.Convert.ToInt32(xinxi("cishu"));
这是什么
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Mall_sysManage_duijiangtwo : System.Web.UI.Page
{
DataBase MySQL = new DataBase(); protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{ int cs,pv;
cs = System.Convert.ToInt32(xinxi("cishu"));
if (cs == 1)
{
pv = 5;
}
else
{
if (cs == 2)
{
pv = 5;
}
else
{
if (cs == 3)
{
pv = 10;
}
else
{
if (cs == 4)
{
pv = 20;
}
else
{
if (cs == 5)
{
pv = 40;
}
else
{
if (cs == 6)
{
pv = 80;
}
}
}
}
}
}
this.Label1.Text = xinxi("cishu");
this.Label2.Text =pv.ToString();
JiangBind();
}
}
private void JiangBind()
{
DataSet ds = MySQL.ExDataSet("select * from [duijiang] where uid=" + ReaderUser(2));
this.jiangRepeater.DataSource = ds.Tables["jiangCart"];
this.jiangRepeater.DataBind();
ds.Clear();
}
protected void postBtn_Click(object sender, EventArgs e)
{
int Num = 50;
if (DateTime.Now.DayOfWeek.ToString() == "Saturday" || DateTime.Now.DayOfWeek.ToString() == "Sunday")
{
Response.Write(" <script>alert('今天是周末,不能对奖,请于星期一再来!');;window.location.href='userJiang.aspx'</script> ");
}
else
{
if (System.Convert.ToInt32(MySQL.ReturnVal("select jifen from users where id=" + ReaderUser(2))) < Num)
{
Response.Write("<script>alert('对不起,您的所余积分已经不足兑换您投奖了.')</script>");
}
else
{
if (MySQL.Execute("insert into toujiang (type,uid,num) values (0," + this.ReaderUser(2) + "," + this.skey.Text.Trim() + ")"))
{
MySQL.Execute("update users set jifen=jifen-" + Num + " where id=" + ReaderUser(2)); Response.Write("<script>alert('您的投奖内容已经提交成功,请等待结果吧.');window.location.href='userJiang.aspx'</script>");
}
else
Response.Write("<script>alert('对不起,投奖失败,请稍候再试.');</script>");
}
}
} private string xinxi(string obj)
{
string id = "";
id = ReaderUser(2);
return MySQL.ReturnVal("select " + obj + " from [duijiang] where uid=" + id);
}
private string ReaderUser(int i)
{
string[] arr = Request.Cookies["loginAdmin"].Value.ToString().Split(','); string rval = ""; for (int j = 0; j < arr.Length; j++)
{
rval = arr[i].ToString();
} return rval;
}
}
int cs;
int pv=0;this.Label2.Text = pv.ToString()我试过了,这样就OK了