By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,395 Members | 2,537 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,395 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.