|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Translating ID bound to label in detailsView to NAME basing on different datasource.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 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 Show quoteHide quote "H5N1" <ha5***@gmail.com> wrote in message news:1144988261.680800.15260@g10g2000cwb.googlegroups.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 > 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
Other interesting topics
New to ASP
Help removing a reference in a web site Anyone care to help explain forms authentication in 2.0? how do yoiu ASP.NET from changing the id attribute???? ASP.NET: Can't Kill EXCEL.exe with Office PIA Update Query in formview Determine Debug Mode Parsing Request.Headers.ToString() asp.net 2.0 connectoin string (hopefully last question) DataGrid Delete Problem |
|||||||||||||||||||||||