PDA

View Full Version : مبتدی: مشکل با property در code-behind



mahsa.n
پنج شنبه 20 آبان 1389, 12:37 عصر
سلام
من وقتی برنامه رو trace میکنم o.count رو برابر با 3 قرار میده و در c عددی درج نمیکنه چرا؟؟؟ من میخوام c برابر با 3 بشه
به خاطر همین وقتی شرکت تیراژه ماشین رو انتخاب میکنم و روی دکمه کلیک میکنم o.count رو 0 برمیگردونه و قسمت if رو اجرا میکنه



protectedvoid Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ContactName ContactName = newContactName();
var query1 = from k in db.ContactNames
selectnew { NameId = k.NameId, FullName = k.FirstName + " " + k.LastName };
DropDownList1.DataSource = query1;
DropDownList1.DataValueField = "NameId";
DropDownList1.DataTextField = "FullName";
DropDownList1.DataBind();
///////
output o = newoutput();
o.count = DropDownList1.Items.Count;
DropDownList1.Items.Insert(o.count, "شرکت تیراژه ماشین");
DropDownList1.Items[o.count].Value = ((o.count) + 1).ToString();
}

}
classoutput
{
privateint c;
publicint count
{

get
{
return c ;

}
set
{
c = value;
}
}
}
protectedvoid btnInsert_Click(object sender, EventArgs e)
{
output d1 = newoutput();
if (DropDownList1.SelectedIndex==d1.count)
{
Response.Write("heloooooooooooooooooooooo");
}
else
{

cjNet
پنج شنبه 20 آبان 1389, 14:19 عصر
این طور که من متوجه شدم فکر کنم اگه متغییر c کلاس output رو static تعریف کنی مشکلت حل بشه .

private static c ;