ASP.NET Web Forms and Databinding

ASP.NET Web Forms and Databinding

Old forum URL: forums.lhotka.net/forums/t/2042.aspx


GrullonM posted on Thursday, December 28, 2006

In Project Tracker (Web Version), I see Gridviews, Detailviews and Formviews binding to different CslaDataSources.

Is it possible to just create  a whole bunch of text boxes and bind directly to them without using the Gridview or Detailsview, etc...? Something along the lines where you create a command object with a connection, creating a reader or dataset/data adapter, then setting the values to the individual textboxes.

An example would be greatly appreciated.

Thanks!

Miguel

GrullonM replied on Thursday, December 28, 2006

After some testing, this seems to be populating the object (at least I can see the values when debugging) Is this a solution worth trying or am I wasting my time and should stick to a FormView?

Protected Sub Save_Application(ByVal sender As Object, ByVal e As System.EventArgs)
   
Try

      
Dim obj As Project= GetProject()

      obj.FirstName    = txtFirstName.Text
      obj.LastName    = txtLastName.Text
      obj.Email            = txtEmail.Text

      SaveProject(obj)

   Catch ex As Exception
      MessageLabel.Text = ex.Message
   End Try

End
Sub

GrullonM replied on Thursday, December 28, 2006

I went ahead and tested the whole thing and it works as I expected... (See Previous post)

The object is created and data is posted back to the database. I guess I can ditch the Detailsview/Formview now and not have to deal with Insert and Edit mode.

JoeFallon1 replied on Thursday, December 28, 2006

Sure.

That technique is very common. One goal is to minimize the amount of that sort of binding code though. I use Rick Strahl's 2 way databinding controls (from 1.1) to handle this. These controls basically have a few extra Properties like BindingSource and BindingMember. By setting these properties to your BO and one of its Properties you get 2 way databinding without writing the code you just demonstrated. The controls are not free though. Under $100, I think. Plus Rick just updated them in 2.0 to be extended controls rather than derived controls. I have not had time to upgrade though.

 

Wbmstrmjb replied on Tuesday, November 25, 2008

Joe,

I know this thread was quite a while ago, but I was wondering if this (http://msdn.microsoft.com/en-us/magazine/cc163505.aspx) is what you were referring to?  It seems that it is now free.

JoeFallon1 replied on Tuesday, November 25, 2008

Yes.

That is exactly what I was referring to. I did not know that Rick wrote an Article on it and then released it. Thanks for pointing that out.

I like the 2.0 extender controls a lot. It lets you avoid sub-classing the stock controls which I had to do in 1.1 and am still living with.

Joe

 

SouthSpawn replied on Tuesday, November 25, 2008

Joe,

How do you use this grid in regards to CSLA?
Can you post some example code.
 
I tried following his examples, but no luck.

JoeFallon1 replied on Wednesday, November 26, 2008

SouthSpawn:
Joe,

How do you use this grid in regards to CSLA?
Can you post some example code.
 
I tried following his examples, but no luck.

I just glanced at the article again I do not know what you are asking. There is no grid. What are you referring to?

Joe

 

SouthSpawn replied on Wednesday, November 26, 2008

JoeFallon1:
SouthSpawn:
Joe,

How do you use this grid in regards to CSLA?
Can you post some example code.
 
I tried following his examples, but no luck.

I just glanced at the article again I do not know what you are asking. There is no grid. What are you referring to?

Joe

 

 

LOL, Been doing too much at once.
 
Sorry about the datagrid comment.
I meant, data binding it to a control.

I am trying to figure out how I use the CLSADatasource in respect to his extended binder?

Thanks

JoeFallon1 replied on Wednesday, November 26, 2008

Do not use the CSLADatasource.

You just set the the extended property on the control in design view and you are done.

You should use one or the other, but not both.

Joe

 

Copyright (c) Marimer LLC