1 protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
2 {
3 LinkButton lbtn = FormView1.FindControl("UpdateButton") as LinkButton;
4 booksTableAdapter adapter = new booksTableAdapter();
5 Label bidLabel = FormView1.FindControl("bidLabel1") as Label;
6 TextBox bnameTextBox = FormView1.FindControl("bnameTextBox") as TextBox;
7 TextBox authorTextBox = FormView1.FindControl("authorTextBox") as TextBox;
8 TextBox produceTextBox = FormView1.FindControl("produceTextBox") as TextBox;
9 TextBox imgTextBox = FormView1.FindControl("imgTextBox") as TextBox;
10 TextBox introTextBox = FormView1.FindControl("introTextBox") as TextBox;
11 DropDownList ddlType = FormView1.FindControl("ddlType") as DropDownList;
12
13
14 string txtbid = bidLabel.Text;
15 string txtbname = bnameTextBox.Text;
16 string txtauthor = authorTextBox.Text;
17 string txtproduce = produceTextBox.Text;
18 string txtimg = imgTextBox.Text;
19 string txtintro = introTextBox.Text;
20 string txtType = ddlType.SelectedValue;
21 if (adapter.UpdateNovel(txtbname, txtauthor, txtproduce, txtimg, txtintro, txtType, txtbid) > 0)
22 {
23 FormView1.ChangeMode(FormViewMode.ReadOnly);
24 Bind(txtbid);
25 }
26 else
27 {
28 Response.Write("<script>alert('更新失败请重试')</script>");
29 }
30 }
控件更新事件已经触发
我自己调试发现取得这些控件的.text值为原来数据库的值,但是自己重新输入的新数据他没有识别
应该是自己去取数据的时机不对
希望解决过此问题的人看看
有一种可能是你在 protected void Page_Load(object sender, EventArgs e) 中重新加载了"原来数据库的值",例如:
protected void Page_Load(object sender, EventArgs e)
{
bidLabel.Text = "某个值";
}
那么你就没有办法得到你修改的新值了.
如果是这样你需要用 Page.IsPostBack 来区别是第一次load页面呢, 还是你提交修改请求.
谢谢 问题解决
解决办法 正如二楼所说的Page.IsPostBack
是不是你使用的事件不对,这个事件不是来干这个的!