Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Intercepting DropDownList Selected Value when not in list of Items

Reply
Thread Tools

Intercepting DropDownList Selected Value when not in list of Items

 
 
WJB
Guest
Posts: n/a
 
      10-31-2007
I'm using a FormView with a number of DropDownList controls that are bound to
SqlDataSources. Sometimes, the current contents of the bound fields are
invalid (i.e. not in the list of items retrieved from the data source used as
the DataSourceID for the dropdown list). Trapping the OnDataBinding event is
too early since the list items and selected index/text have not been
populated yet. Trapping the OnDataBound event is too late as the exception
has already been thrown. The rules I'm working with make such that I cannot
add the invalid item to the list's data source.

Am I understanding this correctly? Is there a way to try..catch an exception
that seems to occur between two events firing? Or there a better way to
accomplish this short of doing it the hard way and replacing the
SqlDataSources with ObjectDataSources and coding the data access myself?

Thanks
 
Reply With Quote
 
 
 
 
Phil H
Guest
Posts: n/a
 
      11-07-2007
On 31 Oct, 00:22, WJB <(E-Mail Removed)> wrote:
> I'm using a FormView with a number of DropDownList controls that are bound to
> SqlDataSources. Sometimes, the current contents of the bound fields are
> invalid (i.e. not in the list of items retrieved from the data source used as
> the DataSourceID for the dropdown list). Trapping the OnDataBinding event is
> too early since the list items and selected index/text have not been
> populated yet. Trapping the OnDataBound event is too late as the exception
> has already been thrown. The rules I'm working with make such that I cannot
> add the invalid item to the list's data source.
>
> Am I understanding this correctly? Is there a way to try..catch an exception
> that seems to occur between two events firing? Or there a better way to
> accomplish this short of doing it the hard way and replacing the
> SqlDataSources with ObjectDataSources and coding the data access myself?
>
> Thanks


Neither an SqlDataSource or an Object DataSource can be used for
individual controls contained within a FormView control separately
from the one that is attached to the FormView control via its
DataSourceID property. You can populate the DDL controls individually
with code in the DataBinding event but you will have to use objects
such as System.Data.SqlClient.SqlCommand +
System.Data.SqlClient.SqlDataReader to do it and write explicit code.
SqlDataSource objects and the associated databind events cannot be
nested as you appear to be trying to do.

Phil Hall

 
Reply With Quote
 
 
 
 
WJB
Guest
Posts: n/a
 
      11-08-2007
Thank you, Phil. I wan't necessarily trying to nest databind events. Rather,
I wanted to try to prevent the DataBound event from firing as the exception
has already occurred. But on the event preceding that, namely the DataBinding
event, the fields have not been populated yet so I cannot test whether the
entered content in the control is valid or not. However, if I explicitly
write the data access code myself as you suggest, I should be able to fully
control the process.

Thanks again for your response.

"Phil H" wrote:

> On 31 Oct, 00:22, WJB <(E-Mail Removed)> wrote:
> > I'm using a FormView with a number of DropDownList controls that are bound to
> > SqlDataSources. Sometimes, the current contents of the bound fields are
> > invalid (i.e. not in the list of items retrieved from the data source used as
> > the DataSourceID for the dropdown list). Trapping the OnDataBinding event is
> > too early since the list items and selected index/text have not been
> > populated yet. Trapping the OnDataBound event is too late as the exception
> > has already been thrown. The rules I'm working with make such that I cannot
> > add the invalid item to the list's data source.
> >
> > Am I understanding this correctly? Is there a way to try..catch an exception
> > that seems to occur between two events firing? Or there a better way to
> > accomplish this short of doing it the hard way and replacing the
> > SqlDataSources with ObjectDataSources and coding the data access myself?
> >
> > Thanks

>
> Neither an SqlDataSource or an Object DataSource can be used for
> individual controls contained within a FormView control separately
> from the one that is attached to the FormView control via its
> DataSourceID property. You can populate the DDL controls individually
> with code in the DataBinding event but you will have to use objects
> such as System.Data.SqlClient.SqlCommand +
> System.Data.SqlClient.SqlDataReader to do it and write explicit code.
> SqlDataSource objects and the associated databind events cannot be
> nested as you appear to be trying to do.
>
> Phil Hall
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help selecting items from a list box trigger by what selected in dropdown list mldardy ASP .Net 1 12-10-2008 02:24 AM
Selected ListItem in DropDownList does not appear selected Nathan Sokalski ASP .Net Web Controls 0 10-05-2008 10:29 PM
Selected ListItem in DropDownList does not appear selected Nathan Sokalski ASP .Net 0 10-05-2008 10:29 PM
DropDownList 2 always returns Selected = 0 for all items - even selected item Iain ASP .Net 3 12-11-2006 11:07 AM
grouping items among a list according to items subtag value Gilles Kuhn XML 0 09-15-2003 12:01 PM



Advertisments