Groups | Blog | Home
all groups > asp.net > february 2004 >

asp.net : Autopostback, binding and losing selection


sklett
2/19/2004 11:28:29 PM
Hi-

I'm a bit rusty cause it's been awhile since I've made an asp.net app, but
here is what I want to do:

single aspx page
bound DropDownList w/ autopost back that holds names of customers
DataGrid that shows customer data

When a user selects a customer from the drop down, I get the selected
value(customer ID) and store it into a member variable (mCustId) then I call
my BindData() method that uses that CustId to filter a DataTable and show
the correct data for that customer.

Everything works except when the Autopostback fires, I don't have the
correct selection in the DropDownList. This is because I'm calling
BindData() which also binds the DropDownList.

The problem is obvious and a basic solution is also obvious (call separate
function just to bind the grid) but this does not seem like a very flexible
solution. Is there some way to make the DropDownList's selectedItem value
persist?

Based on what I have described here(this MUST be a common approach) what is
the standard way to handle this?

Thanks for any tips or help!


Steve

Steve
2/20/2004 7:39:18 AM
OK, thanks for the response. Atleast I know I'm not missing anything now ;)


[quoted text, click to view]

SHENG333
2/20/2004 4:55:57 PM
There is no way to do like your describing.
You should not bind again the dropdownlist in the postback event.

[quoted text, click to view]

AddThis Social Bookmark Button