開發一個NBear作為基礎架構的網站的時候,遇到了一個很變態的問題,自己苦思加從網上都沒有找到相關的解法,只好發帖到首頁來求解,真的很急的一個東西,希望大家體諒。
這個主要問題就是我有一個更新的頁面產品的頁面,在介面載入的時候用下面的代碼初始化的頁面上面控制項的值:
protected void Page_Load(object sender, EventArgs e)
{
SureLogin();
int id = GetIntParam("id", 0);
if (id == 0)
{
Response.Redirect("managegoods.aspx");
}
else
{
dsCategory.Filter(WhereClip.All);
ddlCategory.DataBind();
Goods aGoods =
Gateways.SdaiBuy.Find<Goods>(id);
ddlCategory.SelectedValue = aGoods.GoodsCategory.ID.ToString();
tbMarketing.Text = aGoods.Marketing.ToString ();
tbName.Text = aGoods.Name;
tbPrice.Text = aGoods.Price;
tbStock.Text = aGoods.Stock.ToString();
weIntro.Text = aGoods.Content;
}
}
然後在我更新按鈕裡面寫了下面的代碼更新資料庫:
protected void btnSubmit_Click(object sender, EventArgs e)
{
//上傳圖片
bool fileOK = false;
string path = Server.MapPath("~/UpFile/");
string picname = string.Empty;
if (FileUploadPic.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(FileUploadPic.FileName).ToLower();
string[] allowExtensions ={ ".gif", ".png", ".jpeg", ".jpg", ".bmp" };
for (int i = 0; i < allowExtensions.Length; i++)
{
if (fileExtension == allowExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUploadPic.SaveAs(path + FileUploadPic.FileName);
picname = System.IO.Path.GetFileName(FileUploadPic.PostedFile.FileName);
}
catch (Exception ex)
{
Label1.Text = "失敗";
}
}
//將商品記錄更改加入資料庫
int id = GetIntParam("id", 0);
Goods aGoods =
Gateways.SdaiBuy.Find<Goods>(id);
aGoods.Marketing = Convert.ToInt32 ( tbMarketing.Text);
aGoods.Name = tbName.Text;
if (picname != string.Empty)
{
aGoods.PicPath = "upfile/" + picname;
}
aGoods.Price = Server.HtmlEncode ( tbPrice.Text.Trim ());
aGoods.Stock = Convert.ToInt32 (tbStock.Text);
aGoods.Content = weIntro.Text;
Gateways.SdaiBuy.Save<Goods>(aGoods);
Category aCategory = Gateways.SdaiBuy.Find<Category>(Convert.ToInt32 (ddlCategory.SelectedValue) );
aCategory.ShopGoods.Add(aGoods);
Gateways.SdaiBuy.Save<Category>(aCategory);
Response.Redirect("manageGoods.aspx");
}
發現了一個問題,就是所有控制項的值只能取到我在頁面初始化時給他載入的值,而取不到我在裡面輸入的最新的值,懷疑是不是微軟的東西有錯誤,大家有沒有遇到這個問題的給我說說,謝謝了。