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

H

H5N1

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
 
A

Aytaç ÖZAY

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
 
H

H5N1

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top