.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Use data from First ObjectDataSource as SelectParameter for Second ObjectDataSource

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

I have defined an ObjectDataSource (sourceDocument) to retreive a record from database, the data is returned as a object from a class I programmed myself.

<asp:ObjectDataSource ID="sourceDocument" runat="server" 
                <asp:QueryStringParameter DefaultValue="0" Name="record_id" 
                    QueryStringField="DocID" Type="Int32" />

The object that is returend has a property called "SchoolDocument" which is a Boolean value

I am creating a second ObjectDataSource (sourceTypeList) that returns a DataSet of Doc Types.  I need to use the value of SchoolDocument from the first ObjecDataSource (sourceDocument) in the SelectParameter for the second ObjectDataSource (sourceTypeList).  This what I tired:

<asp:ObjectDataSource ID="sourceTypeList" runat="server" 
            OldValuesParameterFormatString="original_{0}" SelectMethod="GetList" 
                <asp:ControlParameter ControlID="sourceDocument" DefaultValue="false" 

View Complete Post

More Related Resource Links

Binding DataTable data to ObjectDataSource

Hi all, I am trying to bind a DataTable into a ObjectDataSource. This ObjectDataSource data will be used to bind into my LocalReport in ReportViewer. I have already successfully binded my data into the DataTable. My problem now is how do i bind the data in my DataTable into the ObjectDataSource so that it can be used in my report? Here is my current codes: ASPX:<rsweb:ReportViewer ID="ReportViewer1" runat="server"> <LocalReport ReportPath="Modules\Report.rdlc"> <DataSources> <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" /> </DataSources> </LocalReport> </rsweb:ReportViewer> <asp:ObjectDataSource runat="server" ID="ObjectDataSource1"> </asp:ObjectDataSource> VB:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try Dim dtable As DataTable = SetReportDataSource() If dtable.Rows.Count > 0 Then Dim rds As New ReportDataSource() ReportViewer1.LocalReport.DataSources.Clear() ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Data

TableAdapter wizard not giving me choice for tabular data, also ObjectDataSource config wizard not g

Hello, I was wondering if someone could help me with this problem. First of all, I created my own stored procedure in SQL Server for my aspnetdb database which is :USE [C:\USERS\DAVE\DESKTOP\AUG 19 NEW ONE\APP_DATA\ASPNETDB.MDF] GO CREATE PROCEDURE [dbo].[aspnet_GetNotifications] ( @UserName nvarchar(256) ) AS SELECT UserName,UserNotification,UserNotificationDate FROM UserNotifications WHERE UserName=@UserNameSo, the procedure gets everything from the UserNotifications table, except the RecordID(primary key) which is not needed for display.Now I have set up my BLL and DAL, and everything is working fine, in my DAL, I have the tableadapter and it is called PersonalRecordEntries.xsd in which I have added queries to it using existing stored procedures. Such as :GetLastRecordEntryDate(@UserName) which returns one value which of course is the last record entry date.InsertRecord(@UserName,@TDEE,@BMI,@FTM) which does not return any values, it only inserts a record.AND LASTLYGetNotifications(@UserName) which is supposed to return UserName, UserNotification and UserNotificationDate ( I just realized I can also get rid of having to return UserName but whatever)Now problem #1 ( never had problem with other queries because they did not return more than one value) is that when I add the query to QueriesTableAdapter in design mode and use existing stored procedure, and go through all t

want to get Data key value of details view and use in objectdatasource for data list ?



I have a details view and the primary key is CompanyId which retrieves data from a table called companies.


On the same page I have a datalist that is bound to another objectdatasource which has a select method



For the parameter for the OBJ seect method attached to data list, I want to use the DataKey Value for the company that is being displayed in

the details view.


thanks for any solutions to this







ObjectDataSource CancelSelectOnNullParameter="false" // Select all when select parameter is null or


Hi ! I am using an objectdatasource in my project and I want to select all rows when the selectparameter value is empty ! I did the following but I am failling;
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="TugberkUgurluCom_TransferModule.TransferPriceDetailsAll" SelectMethod="GetAllDataFromPricesForControl" TypeName="TugberkUgurluCom_TransferModule.TransferPriceDBComponent" UpdateMethod="UpdateTransferPrices">
    <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="DropDownList1" Name="TpDestID" PropertyName="SelectedValue" Type="

The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be f



I want to display report in aspx page. For that I created Report1.rdlc file and as DataSource DataSet1. After that I created Report1.aspx file and drag the ReportViewer1 and I 'choose the Data Source' and my report. Now when I try to run my aspx file I got the following error

The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be found.


My Report1.aspx file is as follow

<rsweb:reportviewer id="ReportViewer1" runat="server" font-names="Verdana" font-size="8pt" height="400px" width="400px">

LocalReport ReportPath="C:\MAIN\badging\Reports\Report1.rdlc">

what am i doing wrong with this objectdatasource that the DetailsView never gets populated


I want to allow the user to view and edit their information.

So using another example i found online, i got it work, but the example was setup for you to provide the user name and search for the person, since you are already logged into the system i want to pass your username into the code so that on page load the DetailView is populated with your details.

                      <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="UserName" DataSourceID="ObjectDataSource2" Width="400px">
                                <asp:BoundField DataField="PasswordQuestion" HeaderText="PasswordQuestion" ReadOnly="True" SortExpression="PasswordQuestion" />
                                <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName" />
                                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                                <asp:BoundField DataField="CreationDate" HeaderText="CreationDate" ReadOnly="True" SortExpression="Cre

ListView calls ObjectDataSource SelectMethod when setting InsertItemPosition


I have a ListView that is bound to an ObjectDataSource. I want to create a new insert item when the user clicks on a button on the form. I do this by reacting to the button click event on the postback. In the button click event, I set ListView.InsertItemPosition = InsertItemPosition.FirstItem.


        protected void NewButton_Click(object sender, EventArgs e)
            // This line causes the ListView's ObjectDataSource to call its SelectMethod
            // Removing this line, the SelectMethod is NOT called.
            itemsListView.InsertItemPosition = InsertItemPosition.FirstItem;


This works, but for some reason the ObjectDataSource's SelectMethod is executed again.

Is there a reason why the SelectMethod of the ObjectDataSource is being called when the ListView's InsertItemPosition is set from None to FirstItem?


OnPreRender method is Not called last because of objectDataSource

I have an Asp.net web form with several drop down list boxes on it. The way the code is currently set up is that the drop down listboxes are populated through use of an ObjectDataSource via a class named SpottedWeb, as referred to by the TypeName attribute. The problem is that sometimes I need to pre-select drop down list box items, but the ObjectDataSource seems to have the last say in loading the drop down listboxes. So any attempt to pre-select drop down listbox items is undone when my .Aspx code is executed. My attempt to fix this involved creating an OnPreRender method, because I thought it would have the last say with populating my listboxes. But this is not the case.So is there a way that I can have the OnPreRender method or some other C# method be called after the .Aspx page loads my drop downs with the objectDataSource? // Here is my OnPreRender method.         protected override void OnPreRender(EventArgs e)        {            base.OnPreRender(e);             if (Session["Indicator"] != null)            {                PrePopulateWebForm(); // Pre-Sele

Gridview (bound by ObjectDataSource) Sorting - VB.NET

Hello.. I have a gridview being data bound by an objectdatasource which points to a BLL/DAL.  I have paging and sorting enabled within the gridview. I have the fields configured in the look/fell I want from a templatefield.  This templatefield has the sort expression (date) I want things to be sorted by. All this works as it should and I have no issues with it. But, the issue is that when I click on the header to sort asc/desc by date, I have to click on it twice for it switch to descending order.  E.g.  I hit the webpage and it lists all the information in the gridview, sorted by date, ascending order.  If I want to sort by descending order, I have to click the date header twice in order for the gridview to sort the information in descending order; the clicks cause a post-back and the whole screen is refreshed. Any ideas why this may be occurring?  Thanks.. -Jeff  

Control this objectdatasource programatically from the code behind based on different button clicks

I have a page where you can search and display other data, very simple layout. 1 Gridview and 1 objectdatasource. But i have 4 possible buttons that can populate the gridview.. i would like to control my objectdatasource from the code behind based on the button you click. here is what i have right now.. but if possible, can this source not be hardcoded like this and only built in the code behind? <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectDVRInfo" TypeName="DataAccessCode"> <SelectParameters> <asp:ControlParameter ControlID="ddlDVR" Name="dvrInfo" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:ObjectDataSource> I found this site with a solution to this persons issue, but i cant seem to get mine working this way. http://stackoverflow.com/questions/2404264/overwriting-controlparameters-of-datasources-in-code-behind I have  this as the code behind right now when you press the button.. what other parameter settings am i missing and is this the right order to populate them for the source to acknowledge my values?   ObjectDataSource1.SelectMethod = "SelectDVRInfo"; ObjectDataSource1.SelectParameters["MyParameter"]

Gridview Objectdatasource calling funtion while paging

Hi,I am asking this question in bit confused state..I have a Gridview in a page which is bind to function via ObjectDataSource. Function returns dataset. I am returning dataset becuase its disconnected...but when navigating/ or using paging the see a call to the function again.. why is that? if dataset already has data then why it needs to go and make a call to DB again? please explainThanks

How to handle sorting and paging when objectdatasource is being built dynamically?

i am building my objectdatasource dynmically when certain buttons are clicked on the page.. and with that the gridview is being displayed with the results of the objectdatasource that was built. So my gridview code looks like this: <asp:GridView ID="GridView1" runat="server" Visible="False" Width="85%"> <EmptyDataTemplate> There are no results for your search. Please try again. </EmptyDataTemplate> </asp:GridView> How can i enable sorting and paging if the datasource is being built on button click event?

Is it possible to store objectdatasource in session or viewstate to use on another page?

Im building my objectdatasource on different button events.. so id like to know if i can store that or the results in a session or viewstate so i can use it on a pop-up window. explanation: User arrives at our page. They select or enter specific information to search.. results found are presented in a gridview, that is currently bound to the objectdatasource. Within that gridview i will be adding a button to open a new window that will display a googlemap with the location marked on the map. Also will be adding a button to view all the results on the map. So if your search returns 10 records and you want to see all 10 marked on the map, they can click the "View All" button and they are all marked on the map.. Or if you want to just view 1 at a time, you select that record and it display just that record on the map.   So not sure what i should do to accomplish this.

How to pass variable to objectDataSource???

Could someone please help me with this?I have an objectDataSource which uses my stored procedure GetNotificationsAnd my GridView is bound to that objectDataSourcethe only problem is that my stored procedure requires the variable @UserName and then returns the values for that username, but I do not know how to pass the variable to the objectDataSource, does anyone know the code for this?I can get userName from HttpContext.Current.User.Identity.Name but how do I pass that to the objectDataSource?

Is this not possible with objectdatasource?

if (Session["ObjectDataSource1"] != null) { ObjectDataSource ObjectDataSource1 = new ObjectDataSource(); ObjectDataSource1 = (ObjectDataSource)Session["ObjectDataSource1"]; DataSet ds = ObjectDataSource1.Select() as DataSet; Label1.Text = ds.Tables["VideoInfo"].Rows[0]["Latitude"].ToString(); Label2.Text = ds.Tables["VideoInfo"].Rows[0]["Longitude"].ToString(); } Im not getting any errors, but im also not getting any values.. I have a objectdatasource that is built dynamically on a page, when you click a link on that page im opening a new browser window. In that window i need to have access to all the data presented in the main pages gridview, so i wanted to set the objectdatasource that is generated to a session. The above code is what i have on my new browser window. Below is the code i have on my main page:   ObjectDataSource1.SelectMethod = "SelectInfo"; ObjectDataSource1.SelectParameters.Clear(); ObjectDataSource1.SelectParameters.Add("dvinfo", TypeCode.String, ddlDV.SelectedValue.ToString()); ViewState["MethodName"] = "SelectInfo"; Sessio

how to configure objectdatasource

Hello, I was wondering if someone could help me with this problem.   First of all, I created my own stored procedure in SQL Server for my aspnetdb database which is :   view plaincopy to clipboardprint? USE [C:\USERS\DAVE\DESKTOP\AUG 19 NEW ONE\APP_DATA\ASPNETDB.MDF]   GO      CREATE PROCEDURE [dbo].[aspnet_GetNotifications]   (       @UserName               nvarchar(256)   )   AS   SELECT UserName,UserNotification,UserNotificationDate   FROM UserNotifications WHERE UserName=@UserName   So, the procedure gets everything from the UserNotifications table, except the RecordID(primary key) which is not needed for display. Now I have set up my BLL and DAL, and everything is working fine, in my DAL, I have the tableadapter and it is called PersonalRecordEntries.xsd in which I have added queries to it using existing stored procedures. Such as : GetLastRecordEntryDate(@UserName) which returns one value which of course is the last record entry date. InsertRecord(@UserName,@TDEE,@BMI,@FTM) which does not return any values, it only inserts a record. AND LASTLY GetNotifications(@UserName) which is supposed to return UserName, UserNoti

Configuring ObjectDataSource not giving me option to select correct TableAdapter

So, I have 3 table adapters in my dataset, and trying to configure the objectDataSource will not give me the option to select the correct table adapter.I set up a temporary website to illustrate what I am talking about, along with pics, not much, just 4 pics.https://sites.google.com/site/configuringobjectdatasource/The first 2 pics are irrelevant but just in case anyone thinking I don't have it set up properly. The other table adapters are working fine, which I have gridviews being populated etc.Anyways, anyone have any idea why it will not give me the option to select aspnet_GetRecordDatesTableAdapter?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend