469,270 Members | 1,160 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

How to bind to the text element of a checkboxlist web control?

Hello all,

I have googled like crazy for this with no sucess!

I have a dataset containing a table with the following fields

Table===Widths
---------------------------------------------
WidthID---int (primary key)
Width------decimal
IsCustom---bool
MaxWidth--decimal
MinWidth---decimal
-----------------------------------------------

Basically it describes a collection of objects of either fixed size (Width)
or custom size given by the range MinWidth->MaxWidth.

All clear so far?

Now some other element in my database is linked (via a joining table) to a
collection of these avaliable widths.
I want a user to be able to search my database for all elements that have a
certain width (custom or fixed).
I have created a CheckBoxList that is populated with all avaliable widths.
The user simply checks the ones they want.

Now for the question.

I can bind the Primary key (WidthID) to my CheckBoxList control using its
DataValueField property.
I want to bind a custom built string to the text element of the
CheckBoxList....but there isn't one!
There is only a DataTextField property and that specifies the column in the
DataSource that it binds to.

Normally I would use something like...

Text="<%# GetWidths(Container.DataItem) %>

where GetWidths would be something like this...

protected string GetWidths(object o)
{
DataRowView DRW=(DataRowView) o;

if( (bool)DRW[2] )
{
return "Custom("+( (decimal)DRW[3] ).ToString()+"-"+(
(decimal)DRW[4] ).ToString()+")";
}
else
{
return ( (decimal)DRW[1] ).ToString();
}
}

But as there is no text field to bind to I am at a loss.
Am I missing something simple here?
Or will I have to create my own Repeater control with a checkbox and a
label?

Thanks
Sean.
May 20 '07 #1
0 1116

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Egbert | last post: by
4 posts views Thread by dm_dal | last post: by
2 posts views Thread by John Hoge | last post: by
7 posts views Thread by bienwell | last post: by
reply views Thread by =?Utf-8?B?RG90TmV0RGV2?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.