|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
fill ObjectDatasource on requestI have an asp.net 2.0 form with an combo box and an objectdatasource and
a gridview bound to the objectdatsource. I would like to fill the objectdatasource only when the user makes a selection from the combobox. By default the objectdatasource retrieves the data when the page loads. How can I prevent it from retrieving data when the page loads and only on postbacks that the user controls. Haim Hi Haim,
From your post, I understand that you're binding a GridView to an ObjectDataSource which has a ControlParameter associated to a DropDownList.SelectValue. And you don't want the ObjectDataSource to retrieve data on first page load. Please feel free to post here if I've misunderstood anything. First, if you are using declarative syntax to configure the ObjectDataSource and associate it with the DropDownList, I don't think you can prevent it from reading data the first time. As far as I know, there's no event in the ObjectDataSource that you can cancel the data binding. However, you can prevent the GridView to bind to the ObjectDataSource the first time by: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView1.DataSourceID = ""; } else { GridView1.DataSourceID = "ObjectDataSource2"; } } The ObjectDataSource will still read the data but the result is not shown in the GridView on the first page load. If you need to completely prevent the ObjectDataSource from loading data on first page load, you have to construct the ObjectDataSource dynamically. I will depict more on this if you need information on this. Sincerely, Walter Wang (waw***@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Thank you Walter. You understood my scenario completely. That is
exactly the information I need to solve my problem. haim Walter Wang [MSFT] wrote: Show quoteHide quote > Hi Haim, > > From your post, I understand that you're binding a GridView to an > ObjectDataSource which has a ControlParameter associated to a > DropDownList.SelectValue. And you don't want the ObjectDataSource to > retrieve data on first page load. Please feel free to post here if I've > misunderstood anything. > > First, if you are using declarative syntax to configure the > ObjectDataSource and associate it with the DropDownList, I don't think you > can prevent it from reading data the first time. As far as I know, there's > no event in the ObjectDataSource that you can cancel the data binding. > However, you can prevent the GridView to bind to the ObjectDataSource the > first time by: > > protected void Page_Load(object sender, EventArgs e) > { > if (!IsPostBack) > { > GridView1.DataSourceID = ""; > } > else > { > GridView1.DataSourceID = "ObjectDataSource2"; > } > } > > The ObjectDataSource will still read the data but the result is not shown > in the GridView on the first page load. > > If you need to completely prevent the ObjectDataSource from loading data on > first page load, you have to construct the ObjectDataSource dynamically. I > will depict more on this if you need information on this. > > > Sincerely, > Walter Wang (waw***@online.microsoft.com, remove 'online.') > Microsoft Online Community Support > > ================================================== > Get notification to my posts through email? Please refer to > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif > ications. > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues > where an initial response from the community or a Microsoft Support > Engineer within 1 business day is acceptable. Please note that each follow > up response may take approximately 2 business days as the support > professional working with you may need further investigation to reach the > most efficient resolution. The offering is not appropriate for situations > that require urgent, real-time or phone-based interactions or complex > project analysis and dump analysis issues. Issues of this nature are best > handled working with a dedicated Microsoft Support Engineer by contacting > Microsoft Customer Support Services (CSS) at > http://msdn.microsoft.com/subscriptions/support/default.aspx. > ================================================== > > This posting is provided "AS IS" with no warranties, and confers no rights. > Hi.
There is also another solution for your problem (only if you are writing your custom BLL classes): 1. Add new parameter - bool performSearch - to your 'Select' method from BLL. 2. Check value of this parameter in 'Select' method - if it is false, then do not query DB. 3. By default set value of this parameter to false. 4. Set AutoPostback property of DropDownList to true and set performSearch parameter to true in its SelectionChanged event. 5. In ODS.Selecting event pass proper value of performSearch to your 'Select' method. 6. In.ODS.Selected event remeber to set value of performSearch param to false. That's all. I know it looks a bit complicated, but it works and you have completely control of querying DB. Piotrek What about this?
protected void ods_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) { if (!Page.IsPostBack) e.Cancel = true; } Andrew
apply an ItemTemplate dinamically
Getting row index by Event Args... I am trying to hide some textboxes, dropdownlists and labels in datalist Video Player in browser... how do I do? Shuffling rows in a GridView DetailsView Issue. Data diagrams - like the ones in office (excel, word, et al.) Programmatically enabling Validation Controls UserControl with databound repeater drops values on postback AddWithValue NOT working |
|||||||||||||||||||||||