Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Databinding a checkboxlist
Message
From
06/10/2003 18:31:05
 
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00835569
Message ID:
00835573
Views:
14
Dan,

No, you didn't sleep through anything ... it's just that data-binding in ASP.NET is only really implemented in one direction ... as you found out, populating the control is a no-brainer. But, it doesn't really persist back to the server "natively" ... you have to roll your own somewhat. Think about writing your own method that goes through each of your controls and stuffs the new values back into the DataSet. I know, it's a PITA, but that's how it works unfortunately.

~~Bonnie

>In order to present a changeable list of options on a page, I am trying to use the CheckBoxList control which can be dynamically populated from a table. However, I can't seem to figure out what to do with the choices the user makes, since the CBL "looses" it's data source. Perhaps I'm misunderstanding what "databinding" means in .Net?
>
>The control gets populated like so:
>
>
>
>dim DT as DataTable = oDataObj.LoadDataTable("select * from cTable"
>' oDataObj is a class that handles getting data from SQL
>
>cblFoo.DataSource =  DT
>cblFoo.DataTextField = "cOptionName"
>cblFoo.DataValueField = "lSelected"
>cblFoo.DataBind()
>
>
>
>The control populates, no worries. Then the user makes their selections and saves. What I need to be able to do is for each item, pass the primary key (stored in the datatable) plus whether the item was selected or not back to a SQL SP that will handle the update.
>
>However, when I get to the point where I do the save, the cblFoo.Datasource property is set to Nothing. Somewhere the data source gets dumped/disconnected/otherwise becomes nonavailable.
>
>Huh? Perhaps I slept thru that lecture, Perfesser, but doesn't "databind" imply some degree of permanent association between the data source and the control? Or is this another case of MS redefining terminology on unsuspecting developers? (OK, sorry, setting RANT off now). Seriously, although I think I can kludge it by hoping the DataTextField value stays unique, I'd prefer not to and use the record PK instead.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform