NameValueList checkboxlist binding

NameValueList checkboxlist binding

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


nige posted on Tuesday, June 12, 2007

Hi,

i am a csla newbie and would like to be able to bind a namevaluelist to a checkboxlist on a web form. the caveat is that the value of the namevalue pair is a custom object (StatusInfo)  i am using to store the selected property. It has the following properties

ID,Status,Enabled

 

my question is how do i bind the value of the namevaluelist (statusinfo object) to the selectedvalue and datatextfield and checked properties of the checkboxlist.

I need this to be two way so that if checkbox is checked the enabled property would be set on the child statusinfo object.

 

RockfordLhotka replied on Tuesday, June 12, 2007

You can't use NVLB for this purpose, you need to create a BusinessListBase/BusinessBase type collection, because that's how you get editable objects (for your selected property).

nige replied on Tuesday, June 12, 2007

thanks for your reply, i was wondering on a similar issue how you bind to a selected property of a business object if it is a nested property within the class

e.g.

customer.address.streename

i know is is a problem with ojectdatasource in terms of two way binding at least, is this still an issue when using csladatasource?

 

RockfordLhotka replied on Tuesday, June 12, 2007

You create one CslaDataSource per object-to-which-you-want-to-bind.

 

Or you use the dynamic binding statements in your ASPX markup (that allows you to bind to arbitrary values, call methods, etc).

 

Personally I go for the first option and create one CslaDataSource per object.

 

Rocky

 

From: nige [mailto:cslanet@lhotka.net]
Sent: Tuesday, June 12, 2007 9:52 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] NameValueList checkboxlist binding

 

thanks for your reply, i was wondering on a similar issue how you bind to a selected property of a business object if it is a nested property within the class

e.g.

customer.address.streename

i know is is a problem with ojectdatasource in terms of two way binding at least, is this still an issue when using csladatasource?

 



nige replied on Tuesday, June 12, 2007

Sorry to be stupid, but not sur i follow what you mean, if i am trying o bind a complex object to a databound control (checkboxlist or otherwise) how do i assign a child property of the object to the control with a seperate csladatasource, how would i link the two datasources together? wouldn't this have to be done in the databinding event? as i would want each row to access this property not just rows that are being edited

thanks

 

RockfordLhotka replied on Tuesday, June 12, 2007

Sorry, misunderstood what you were asking.

 

The answer is to create a UI “helper” object that reshapes the data from your business object into a form that matches what the UI is looking for. This helper object would merely delegate all its calls to the real object, but would expose properties as needed by the UI.

 

Public Class CustomerReshaper

  Private _original As Customer

  Public Sub New(original As Customer)

    _original = original

  End Sub

 

  Public ReadOnly Property Name() As String

  Get

    Return _original.FirstName & “ “ & _original.LastName

  End Get

  End Property

 

  ‘ …

End Class

 

That sort of thing.

 

Rocky

 

 

From: nige [mailto:cslanet@lhotka.net]
Sent: Tuesday, June 12, 2007 11:34 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: NameValueList checkboxlist binding

 

Sorry to be stupid, but not sur i follow what you mean, if i am trying o bind a complex object to a databound control (checkboxlist or otherwise) how do i assign a child property of the object to the control with a seperate csladatasource, how would i link the two datasources together? wouldn't this have to be done in the databinding event? as i would want each row to access this property not just rows that are being edited

thanks

 



Copyright (c) Marimer LLC