469,299 Members | 2,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Translating ID bound to label in detailsView to NAME basing on different datasource.

Hi there

First of all excuse me posting such simple (I guess) question, but I
didn't find the answer in tutorials.
I have a formView presenting records from some table. one of the fields
is a Category ID, which is a foreign key. in edit template I replace it
with dropdownlist, which is gets this ID, and displays corresponding
name, by getting information from other datasource.

it's possible, since we have 3 properties in ddlist:

( DataSourceID="odsCourseCategories" )
DataTextField="Name"
DataValueField="CourseCategoryID"
SelectedValue='<%# Bind("CourseCategoryID") %>'

DataTextField, and DataValueField which are connected to 'foreign'
dataSource, and SelectedValue which is bound to current dataSource
(inherited from parent FormView).

Now, my problem is simple - how can I achieve the same with simple
label control, on the same field, in ItemTemplate (when I'm not
editing), which doesn't (I guess) have those properties?

Label is bound to Category ID, and I want it to display corresponding
Name.

I know that I could tweak my formview datasource (tableAdapter) to
provide Name also, but I'd like to do it using 2 plain single-table
CRUD datasources.
thanks a lot
greets
Hapiec

Apr 14 '06 #1
2 1481
Hi,
You can't use a label inside a DataList or gridview like this. If you want
to save CategoryID you can use DataKeyNames and CategoryID is not listed
when you use your grid, but your label shows your Name field properly.

Have a nice work,

Aytaš ÍZAY
Software Engineer

"H5N1" <ha****@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
Hi there

First of all excuse me posting such simple (I guess) question, but I
didn't find the answer in tutorials.
I have a formView presenting records from some table. one of the fields
is a Category ID, which is a foreign key. in edit template I replace it
with dropdownlist, which is gets this ID, and displays corresponding
name, by getting information from other datasource.

it's possible, since we have 3 properties in ddlist:

( DataSourceID="odsCourseCategories" )
DataTextField="Name"
DataValueField="CourseCategoryID"
SelectedValue='<%# Bind("CourseCategoryID") %>'

DataTextField, and DataValueField which are connected to 'foreign'
dataSource, and SelectedValue which is bound to current dataSource
(inherited from parent FormView).

Now, my problem is simple - how can I achieve the same with simple
label control, on the same field, in ItemTemplate (when I'm not
editing), which doesn't (I guess) have those properties?

Label is bound to Category ID, and I want it to display corresponding
Name.

I know that I could tweak my formview datasource (tableAdapter) to
provide Name also, but I'd like to do it using 2 plain single-table
CRUD datasources.
thanks a lot
greets
Hapiec



Apr 14 '06 #2
Thanks, so there's no declarative way (ie. through control's
properties) to achieve this, but if so, what is the simplest way to
achieve this programmatically?

I guess I should use the ItemDataBound event, and there, using the
CATEGORY ID value (which is foreign key) bound to label, query the
other objectDataSource (representing CATEGORIES table) to check
corresponding NAME value, and substitute with it the current label
value.

the only problem is I don't know how could I perform programmatic query
on object data source, let say something like:
name = categoriesObjectDataSource.Select("Select Name from Categories
where id=currentID");

I can find only examples with binding ODS to controls, couldn't find
any using it to get some values programmaticaly.
thanks a lot
Hapiec

Apr 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Shawn Wildermuth | last post: by
4 posts views Thread by Dabbler | last post: by
1 post views Thread by Jim McGivney | last post: by
4 posts views Thread by Tomasz Jastrzebski | 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
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.