Click here to Skip to main content
15,913,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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




hope it helps.
goodluck. :)


-chaosgray-
 
Share this answer
 
Comments
Monjurul Habib 9-Jun-11 17:44pm    
nice answer, my 5.
Thank you for the input.
Your help was greatly appreciated.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900