Forms Data Controls :: DataBinding To Business Object And Retrieving That Object Later?

Jun 17, 2010

Again, I am new to the ASP.NET world, and I come from a Windows Forms background. I'm working with an ObjectDataSource that retrieves a collection of business objects. With the collection, I am going to be binding it to a CheckBoxList and other various controls. The business object that I am using is an Employee.

To get all of the employees, I create an ObjectDataSource and set the "Select" method. I then set the DataSourceID of the CheckBoxList to be that of the ObjectDataSource. When I load the page for the first time, I see all of the employees. Now, the user goes through this page and selects all the employees they want to see information about (by checking the box next to the employee name). Finally, the user hits the button called "Display." Upon postback how do I get a list of those employees? I've tried the following solution, but I'm not sure if it's the best practice in obtaining all those employees again. Here's my solution...

In the CheckBoxList, I set the DataTextField to the Employee's name. I also set the CheckBoxList's DataValueField. This property is a little different. I set this to be a UNIQUE IDENTIFIER, which can distinguish this employee from other employees. Now, when the user hits the button "Display" I use my ObjectDataSource again and MANUALLY call ObjectDataSource.Select(). I cast the returned value as a List<Employee>. Finally, I iterate through all list items in the CheckBoxList...

[Code]....

If the item is selected, I parse through my list of employees that was returned from the bjectDataSource.Select(). I use the item.Value and compare it to each employee's "key." If the key is found, I know that the employee is selected. I put this employee in another list called EmployeesSelected.

Finally, I take EmployeesSelected (which is a List) and set my GridView's .DataSource and call .DataBind() on the GridView.

Is this the "best practice" of re-obtaining the Employees that are selected on my page, or am I making this too complicated?

View 1 Replies


Similar Messages:

Forms Data Controls :: Trying To Use Dynamic Object In A Databinding Tag

Sep 18, 2010

im trying to use dynamic object in a databinding tag , it gives me error that the property does not exists even though i can see all the properties there in the vs debug mode

here is what im trying to do:

C#:

my method signature:

public static dynamic MyMethod()

ASPX:

in control itemtemplate:

<%# MyMethod().SomeProperty %>

if also trite the other way:

C#:

public static object MyMethod()

ASPX:

<%# ((dymanic)MyMethod() ).SomeProperty%>

But i dont know why it cant resolve the properties , even though i can see them when the databinder control throws an exception (its working fine outside the databinder tag (ie normal aspx tags <% %>)

View 1 Replies

Forms Data Controls :: DetailsView BoundFields Auto Binding Not Updating Business Object On Update

Feb 18, 2010

I have a DetailsView (DV) control, an ObjectDataSource (ODS) control, and a button on a page. I have 2 classes in the App_Code directory (Customer and CustomerDAO). The DAO class provides static methods for the ODS control and simply hack values in (ie...no real database selects/updates). The Customer class has 2 properties (Id and Name) and a default constructor. The page takes an ID on the querystring and determines if the DV control is in insert or edit mode. If in edit mode, it sets the SelectParameter on the ODS (id field), calls ODS.Select(), and then calls DV.DataBind(). The existing (although fake) customer is loaded and display properly when this happens. I then change the name of the Customer in the DV and click the Button to save the new data.

Everything seems to be wired up correctly as the UpdateMethod that is specified in the ODS control is called and succeeds (even in my real example with my database). The problem is that the BoundFields in the DV control have not been updated with the new values and therefore the existing values are updated in the database and my changes are lost. I have handled the OnUpdating event of the ODS and the values are still the old values. I have also handled the OnItemUpdating event of the DV control and the NewValues IOrderedDictionary still has the old values in it also. In looking at the MSDN article for the UpdateMethod, it states the following:

Parameter Merging
Parameters are added to the UpdateParameters collection from three sources:

From the data-bound control, at run time.
From the UpdateParameters element, declaratively.
From the Updating event handler, programmatically.

I am using the BoundField classes in my DV control so I would have assumed that the first bullet above would have handled the updating of values, but it doesn't appear to work with the way I am doing it. If I set the values explicitly in the OnUpdating event that is fired by the ODS control (the 3rd bullet) the right values are updated (again...even in my real database situation). It seems like my only issue is that the automatic binding that I expect from the DV control isn't working as I would expect it to. Here is the code that I have in my fake example:

[Code]....

View 7 Replies

DataSource Controls :: Object Data Source Not Picking Up Business Objects?

Mar 26, 2010

I created a class library: PRTreatmentReviews. I created a reference for the class library on the website. I checked the property pages and the reference to the class is there. I put objectdatasource on a page and tried to pick up the PRTreatmentReviews class but it's not there? The Class

[Code]....

View 13 Replies

Data Controls :: Add GridView Data To Custom Business Object List

Nov 14, 2013

This is My Method, How to get Checkbox Value from Gridview and adde that value inti list?
 
private List<ActivityList> PopulateData() {
string ActivityCode = string.Empty;
string ActivityName = string.Empty;
List<ActivityList> list = (List<ActivityList>)Session["ActivityToStudent"];
List<ActivityList> listObj = (List<ActivityList>)Session["ActivityToStudent"];
for (int j = 0; j < listObj.Count; j++)

[Code] ....

View 1 Replies

Forms Data Controls :: How To Set Height And ItemSource (Business Object As DataSource For Cell) For Every Cell

Mar 24, 2010

How to set Height and ItemSource(Business Object as DataSource for Cell) for every Cell in DataGrid/ Grid? Shown below is part of code I am currently using with Grid Control. What I am currently doing is that I am using ListBoxItem, set Item Height and ItemSource at ListBoxItem Level, Add ListBoxitem to ListBox and then Add ListBox to Grid, It leaves me with just one row and multiple columns in the Grid, which is perhaps not the best way of doing it as it doesn't allow me to take benefits from UI Virtualization of Grid.

[code]....

I am open to use any control i.e. Grid/ DataGrid provided it allows me to set Cell Height and item source at Cell level. In my requirement, Cell height depends on the Item duration and size of image, which means the height of the cells may not be same across cells in any particular row.

View 3 Replies

Architecture :: Insert Data With Business Object?

May 29, 2010

I do not know how to create a business object for inserting data into the database.

View 2 Replies

Forms Data Controls :: Object Reference Not Set To An Instance Of An Object Repeater Control

Apr 21, 2010

can you please help me to brainstorm the possible causes of this error. I've got a paged repeater with localisation bound programitcally to an sqldatasource using a stored proc. I can post code if needs be but it's rather long. I'm looking for typical causes of this error + will make note for future reference!

erver Error in '/WebSite4' Application.

Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

[Code]....

Line 233:Line 234: Repeater1.DataSource = PagedResultsLine 235: Repeater1.DataBind()Line 236: doPaging()Line 237: End Sub

View 9 Replies

Forms Data Controls :: Get The Value Of The Id Field In Gridview/Object Reference Not Set To An Instance Of An Object

Feb 1, 2010

I am trying to get the value of the id field in my gridview but I keep coming up with this error when i do selectedValue or selecteIndex

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

How do I get that id? What I am trying to do is when the user select that link it will delete that information from the database. Here's my code:

[Code]....

[Code]....

View 5 Replies

Forms Data Controls :: Get Error : Object Reference Not Set To An Instance Of An Object

Dec 2, 2010

I have a nested gridview

i get error:Object reference not set to an instance of an object

when i try to get the text in the footer template of the inner gridview when clicking on the linkbutton!!!

[code]....

View 5 Replies

Forms Data Controls :: Error : Object Reference Not Set To Instance Of The Object

Feb 3, 2010

I am using C# and VS 2008 attached with access database, where Date1 is the PKey in Text defined.

I am getting the above error when i am trying to insert it into the access database.

here is my code

aspx :

[Code]....

Code Behind :

[Code]....

View 5 Replies

Forms Data Controls :: Get An "Object Reference Not Set To An Instance Of An Object?

Nov 14, 2010

My problem is I get an "Object reference not set to an instance of an object." error at runtime on the line "ddl2.SelectedValue = cat1". Ironically I got this from an example on the internet and the only difference is my Cat1 varible which has the correct value at runtime.

<asp:FormView
id="frmCustomer"
DataSourceID="srcCustomer"[code]....

View 15 Replies

Forms Data Controls :: Gridview And Object Reference Not Set To An Instance Of An Object?

Jul 10, 2010

I would like to enable/disable the field BagNo in my gridview, depending on the value of another field in the gridview called ScriptNo, when I click the edit button I get this message "Object reference not set to an instance of an object".

here is the code

Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
Dim row As GridViewRow = GridView1.Rows(e.NewEditIndex)
If DirectCast(row.FindControl("ScriptType"), TextBox).Text = "TTA" Then

[Code]....

View 6 Replies

Forms Data Controls :: Cannot Access Header Row Error / Object Reference Not Set To An Instance Of An Object

Jul 2, 2010

I tried to get the heade row text with the following code, but it failed.

[Code]....

Error returned was "Object reference not set to an instance of an object." on this line:

[Code]....

View 3 Replies

DataSource Controls :: Choose Business Object Empty

Feb 17, 2010

I've created my dataset in my App_Code folder. I tested it so it works, But then when I add in my page an ObjectDataSource, it can find any object the list is empty. I looked for online some solution but I didn't find something which worked. It works when I add the code manually, but i would like to understand how come, which part I misunderstood.

[Code]....

View 6 Replies

DataSource Controls :: On DB Change Want To Call Business Object?

Feb 27, 2010

I want to call my business object class in which I have written my logic when any database status field change, what is the best way we can do, I want notification facility also.

I can do this window service. But there is any best way to acheive this like Notification and call my business object.

View 1 Replies

Forms Data Controls :: Grid View OnDataRowBound Error: Object Reference Not Set To An Instance Of An Object?

Jul 2, 2010

The stored proc fired to populate my grid view gets a column CasNo.The GridView has a DataBound item for CaseNo.

[Code]....

Then Why does this get null value: string caseNo = dataRow["CaseNo"] as string;
[Code]....

[Code]....

View 14 Replies

Forms Data Controls :: How To Access A LinkButton Inside A Repeater/Object Reference Not Set To An Instance Of An Object

Jan 16, 2010

why I get this error:

Object reference not set to an instance of an object.

when I try to access a LinkButton inside a Repeater as follows:

[Code]....

[Code]....

View 4 Replies

Forms Data Controls :: ItemTemplate And EditTemplate Rowdatabound Trigger/ Object Reference Not Set To An Instance Of An Object

Sep 7, 2010

I need to change the row.forecolor = drawing.color.red.

in my gridview i have a STATUS field, its ItemTemplate is LABEL1 and its EditTemplate is DropDownList1.

on loading I have successfully changed the forecolor, but when I edit it gave me an error:

Object reference not set to an instance of an object.

View 7 Replies

Forms Data Controls :: Object Reference Not Set To An Instance Of An Object

Oct 15, 2010

I get the error:

Object reference not set to an instance of an object

View 1 Replies

Forms Data Controls :: Object Reference Not Set To An Instance Of An Object?

Nov 11, 2010

Im facing a very complicated problem when i tried to view in browser. It shows the above error and i notice it highlights the line code below :

Line 733: Dim CurrentPoint As Double = CType(txt_point.Text, Double)

Stack Trace:

[Code]....

[Code]....

View 3 Replies

Forms Data Controls :: Object Reference Not Set To Instance Of An Object

Apr 12, 2010

I'm getting this error with this code:

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
' display placeholder image if no imageId
Dim ltrImage1 As Literal = CType(e.Item.FindControl("Image1"), Literal)
Dim ltrImage2 As Literal = CType(e.Item.FindControl("Image2"), Literal)
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
If String.IsNullOrEmpty(drv("ImageId").ToString) Then
ltrImage1.Text = "<img src=""images/properties/x_thumb.gif"" alt="""" />"
ltrImage2.Visible = False
End If
End Sub

I want to set the image if no rows are returned.

View 4 Replies

Pass Key Of Grid To Business Class Via Object Data Source?

Sep 15, 2010

In ASP.NET Webforms have an ASP.NET GridView connected to a C# class via an object data source

I have an ID set up as a DataKeyName in the grid. How do I pass this to the C# class when I update the grid?

View 15 Replies

Pass Key Of Grid To Business Class Via Object Data Source

Jan 21, 2011

In ASP.NET Webforms have an ASP.NET GridView connected to a C# class via an object data source

I have an ID set up as a DataKeyName in the grid. How do I pass this to the C# class when I update the grid?

View 2 Replies

Forms Data Controls :: Object Reference Not Set To An Instance Of An Object In Nested Repeater Control Of CheckBox List ...

Sep 24, 2010

[Code]....

I am getting error of in Foreach loop

[Code]....

How to resolve this situation or any other alternative to cum out of this problem.

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved