c# - GridView not updating from SelectedIndexChange event of a DropDownList within an UpdatePanel -
my problem:
an updatepanel holds dropdownlist , gridview. gridview populate baseds on value stored in label , value selected dropdownlist. not populate on pageload; populates when query string present or when button pressed, there no code in !ispostback
. gridview populated initial selectedvalue of dropdownlist, , want gridview repopulate when selectedvalue of dropdownlist changes.
the thing is... change! once. gridview populates data using value of default selectedvalue of dropdownlist. when selectedvalue changed, data in gridview changes. once. after changing dropdownlist value second time or more, nothing happens.
<asp:updatepanel runat="server" id="theupdatepanel" updatemode="conditional" childrenastriggers="true"> <contenttemplate> <asp:dropdownlist runat="server" id="thedropdownlist" onselectedindexchanged="thedropdownlist_onselectedindexchanged" enableviewstate="true" autopostback="true" /> <asp:gridview id="thegridview" runat="server" autogeneratecolumns="false"> <columns> ... </columns> </asp:gridview> </contenttemplate> </asp:updatepanel>
theupdatepanel's updatemode conditional, updates when children postback. childrenastriggers true, children cause update.
thedropdownlist's autopostback true, postback on change. enableviewstate true (false makes not load). selectedindexchange links right function, , know it's getting called putting break inside during debug mode.
here selectedindexchanged method:
public void thedropdownlist_onselectedindexchanged(object sender, eventargs e) { //get value stored in thelabel - know value correct every time int thevaluefromthelabel = int32.parse(thelabel.text); //populate thegridview data db thegridview_populate(thevaluefromthelabel); //update theupdatepanel (it works first change whether line here or not) theupdatepanel.update(); }
i've tried both , without updatepanel.update();
method, , it's same result: first change of thedropdownlist's value works, , every following change nothing.
the function populate gridview pretty simple:
protected void thegridview_populate(int thevaluefromthelabel) { //get value thedropdownlist - value change when thedropdownlist's value changes int thevaluefromthedropdownlist = int32.parse(thedropdownlist.selectedvalue); //get data db - data here change every time thedropdownlist's value changed complexclasscontroller controller = new complexclasscontroller(); list<complexclass> data = controller.getdata(thevaluefromthelabel, thevaluefromthedropdownlist); //load thegridview - changes data, doesn't refresh thegridview able see thegridview.datasource = data; thegridview.databind(); }
any ideas? must misunderstanding events behind updatepanel.
what valuelabel? doesn't ever gets changed?
why not ((dropdownlist)sender).selectedvalue value redatabind gridview with?
kev
Comments
Post a Comment