首页 新闻 会员 周边

为什么我的FormView控件无法更新

0
悬赏园豆:50 [已解决问题] 解决于 2011-12-13 10:03
View Code
 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值为原来数据库的值,但是自己重新输入的新数据他没有识别
应该是自己去取数据的时机不对
希望解决过此问题的人看看

唯吴独尊的主页 唯吴独尊 | 小虾三级 | 园豆:707
提问于:2011-12-12 18:11
< >
分享
最佳答案
0

有一种可能是你在    protected void Page_Load(object sender, EventArgs e) 中重新加载了"原来数据库的值",例如:

  protected void Page_Load(object sender, EventArgs e)
    {

bidLabel.Text = "某个值";

}

那么你就没有办法得到你修改的新值了.

如果是这样你需要用 Page.IsPostBack 来区别是第一次load页面呢, 还是你提交修改请求.

收获园豆:50
拥有的都是恩典 | 菜鸟二级 |园豆:389 | 2011-12-13 05:36

谢谢 问题解决
解决办法 正如二楼所说的Page.IsPostBack

唯吴独尊 | 园豆:707 (小虾三级) | 2011-12-13 10:03
其他回答(1)
0

是不是你使用的事件不对,这个事件不是来干这个的!

小小刀 | 园豆:1991 (小虾三级) | 2011-12-12 23:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册