2014年7月13日 星期日

[RESOLVED] Dropdownlist Control Not Getting Values?


I have a web form that has a detailsview control with a dropdownlist control inside a template field.  The dropdownlist control is getting the data from a sqldatasource, but I'm getting an error, "DataBinding: 'System.Data.DataRowView' does not contain a
property with the name 'MedFacilitiesType'.


I know from my reading that this usually means the name given in the DataTextField or the DataValueField doesn't match the field name in the database.  But that's not the case - they match.


Here's the code for the detailsview control:


                            






















Here's the code for the sqldatasource:





Not sure what I'm doing wrong?!



Are you sure sdsMedFacilitiesUpdate also has MedFacilitiesType in the selectcommand?



It does not.  I didn't think it was necessary since they draw on two different tables - they're independent of one another, aren't they?



If you use Bind/Eval, make sure that field exist in the results


SelectedValue='<%# Bind("MedFacilitiesType")%>' 

MedFacilitiesType should exist in sdsMedFacilitiesUpdate



Thanks, but I'm not sure I understand.


SelectedValue='<%# Bind("MedFacilitiesType")%>' 

"MedFacilitiesType" is the field from the database whose values are being used to fill the dropdownlist control.  They match.



sdsMedFacilitiesType is DataSource to fill dropdownlist with MedFacilitiesType as DataTextField and DateValueField (It's OK)


sdsMedFacilitiesUpdate is DataSource to fill GridView, If you have any BoundField, Eval, Bind etc, the fieldname should exist in sdsMedFacilitiesUpdate selectcommand/sp


If you use Bind() in EditItemTemplate, you should have parameter name in the UpdateParameter also (two way binding)


Can you show whole coed?



Thank you again.  I see what I was doing wrong.  The Bind() was not referring to a parameter in the sqldatasource that was populating the dropdownlist control.


It works now.


Thanks for your time.


沒有留言:

張貼留言