data binding - When is DataBind called automatically on an ASP.NET page? -


i have gridview on page search button. gridview not visible start user must click search before results retrieved. datasourceid set id of objectdatasource. when click called, following method called click handler:

private void populategrid() {     gv.visible = true;     gv.databind(); } 

a problem occurs when same method called page_load handler. store user's search terms in session , retrieve them first time page accessed, this:

if(!postback && session["search"] != null) {    setsearchfromsession();    populategrid(); } 

the problem in case objectdatasource's selecting event fired twice. once when gridview made visible, , again when databind() called. fixed substituting gv.visible = true; populategrid(); in page_load.

but i'd understand going on. why setting gridview visible page load result in databinding when call in button click event doesn't?

if declaratively set datasourceid going called after prerender , if call databind called again. (twice)

databinding

raised after control's prerender event, occurs after page's prerender event. (this applies controls datasourceid property set declaratively. otherwise event happens when call control's databind method.)

this event marks beginning of process binds control data. use event manually open database connections, if required, , set parameter values dynamically before query run.

source


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -