当DropDownList不变时,GridView不会显示更新的数据. [英] GridView doesn't show updated data when DropDownList doesn't change.

查看:93
本文介绍了当DropDownList不变时,GridView不会显示更新的数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP.NET的新手.

当DropDownList的SelectedIndex值不变时,如何获取GridView以显示更新的数据?我尝试直接调用DropDownList.SelectedIndexChanged(sender,e)使其开始.

我在页面上有一个DropDownList(TabIndex 1),2 TextBox(TabIndex 2&3)控件和一个Button(TabIndex 4)和一个GridView(TabIndex 5).
GridView绑定到下拉列表选择. T
在文本框和按钮控件上,AutoPostBack为True.
Textbox1是必填信息.
Textbox2是可选的.
单击按钮"后,它将更新数据库并清除两个文本框控件. Textbox1_TextChanged具有Page.SetFocus(TextBox2). (之所以这样输入,是因为如果用户按下Enter键,页面将关闭并将我发送回上一页.这可能是一种更聪明的方法.)

问题是用户填写了TextBox1(没有点击Tab或Enter).然后直接单击按钮"控件. TextBox1控件运行,然后看起来"像Button控件运行(Button控件具有清除TextBox1和2的代码,将DropDownList和GridView数据源与控件绑定,并设置DropDownList的SelectedIndex),但实际上没有.我知道这是因为TextBox1&2不会被清除,并且GridView不会显示修改后的数据.
(GridView仅在将新项目添加到DropDownList时才起作用(SelectedIndex =一个数字).当我将数据更新到DropDownList上的现有项目时,它不会使用新数据更新GridView.我认为这是因为它使用相同的数字.)

非常感谢您的帮助.

Hi, I am a novice with ASP.NET.

How do I get the GridView to show the updated data when the DropDownList''s SelectedIndex value doesn''t change? I tried calling the DropDownList.SelectedIndexChanged(sender, e) directly to kick it off.

I have a DropDownList (TabIndex 1), 2 TextBox (TabIndex 2 & 3) control and a Button (TabIndex 4) and a GridView (TabIndex 5) on a Page.
The GridView is tied to the Drop Down list selection. T
he AutoPostBack is True on the Textbox and Button controls.
Textbox1 is required info.
Textbox2 is optional.
When the Button is clicked, it updates the database and clears out both textbox controls. Textbox1_TextChanged has Page.SetFocus(TextBox2). (The reason I put that in is because if the user hits the Enter key, the Page closes and sends me back to the previous page. There''s probably a smarter way to do this.)

The problem is the user fills in TextBox1 (doesn''t hit Tab or Enter). Then clicks on the Button control directly. TextBox1 control runs, then it "looks like" the Button control runs (Button Control has code to clear TextBox1 & 2, databind the DropDownList and the GridView datasources and control, and set the SelectedIndex of the DropDownList), but it does not. I know this because the TextBox1 & 2 do not get cleared out and the GridView doesn''t show the revised data.
(GridView only works when I add a new item to the DropDownList (SelectedIndex = a number). When I update the data to an existing item on DropDownList, it doesn''t update the GridView with the new data. I figure it is because it is using the same number.)

Any help is greatly appreciated.

推荐答案

hi.

尝试将gridview放在"PageLoad"或"PageRender"中

像这样的人.

hi.

try putting your gridview in a "PageLoad" or in the "PageRender"

like this one.

Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
    GridView1.DataBind()
End Sub







Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
      GridView1.DataBind()
  End Sub





希望对您有帮助.
祝你好运. :)


-chaosgray-





hope it helps.
goodluck. :)


-chaosgray-


感谢您的输入.
非常感谢您的帮助.
Thank you for the input.
Your help was greatly appreciated.


这篇关于当DropDownList不变时,GridView不会显示更新的数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆