Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   DropDown List - Default Item - Two RowFilters possible? (http://www.velocityreviews.com/forums/t773012-dropdown-list-default-item-two-rowfilters-possible.html)

Harry 04-15-2004 01:09 PM

DropDown List - Default Item - Two RowFilters possible?
 
Hi,

I have a problem with the default Item of an asp:dropdownlist.

I databind the dropdown list in the code with values from a SQL
Database as per below.

ViewOptions.RowFilter = "Code LIKE 'MM%'";
ddlRam.DataSource = ViewOptions;
ddlRam.DataTextField = "Name";
ddlRam.DataValueField = "IncPrice";
ddlRam.DataBind();

But what I would like now, is for the default option to be set to a
different value based on the below filter:
ViewOptions.RowFilter = "PrRange LIKE 'S' AND Code Like 'MM%'";


Can anyone tell me if this is actually possible.
(Ideally something like the below line would be perfect, if it
worked!!)
ddlRam.SelectedItem = ViewOptions.RowFilter = "PrRange LIKE 'S' AND
Code Like 'MM%'";


ANy help appriciated as always.

Thanks
H

Fred Hirschfeld 04-15-2004 02:31 PM

Re: DropDown List - Default Item - Two RowFilters possible?
 
You cannot do this like you have indicated, but after the bind you could
look through your DataSet (after your selection filter) and use the
..Selected = true of the items in the ddlRam dropdown that match the filtered
results.

You could also package this up as a new function on a derived dropdownlist
to you could use a filter clause for selected items...

Fred

"Harry" <harrysingh1976@hotmail.com> wrote in message
news:1c234377.0404150509.37d966ba@posting.google.c om...
> Hi,
>
> I have a problem with the default Item of an asp:dropdownlist.
>
> I databind the dropdown list in the code with values from a SQL
> Database as per below.
>
> ViewOptions.RowFilter = "Code LIKE 'MM%'";
> ddlRam.DataSource = ViewOptions;
> ddlRam.DataTextField = "Name";
> ddlRam.DataValueField = "IncPrice";
> ddlRam.DataBind();
>
> But what I would like now, is for the default option to be set to a
> different value based on the below filter:
> ViewOptions.RowFilter = "PrRange LIKE 'S' AND Code Like 'MM%'";
>
>
> Can anyone tell me if this is actually possible.
> (Ideally something like the below line would be perfect, if it
> worked!!)
> ddlRam.SelectedItem = ViewOptions.RowFilter = "PrRange LIKE 'S' AND
> Code Like 'MM%'";
>
>
> ANy help appriciated as always.
>
> Thanks
> H




Harry Singh 04-15-2004 05:01 PM

Re: DropDown List - Default Item - Two RowFilters possible?
 
Thans for the reply Fred.
Is there any chance you could provide more details on your proposed
solution.
(Link to sample would be fine, and then i'll try to work ou for myself!)

I don't really understand how I would put your suggestions into
practice!

Many thanks
H




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Fred Hirschfeld 04-16-2004 03:37 AM

Re: DropDown List - Default Item - Two RowFilters possible?
 
I don't actually have some specific, but I will try some directly here (not
compiled...). Hope this gets you closer to what you are looking for... This
may not be optimal in terms of performance but should demonstrate what I was
indicating:


public class FilterSelectDropDownList : DropDownList {
private string m_FilterCriteria = string.Empty;

public FilterSelectDropDownList() : base() {
}

public string FilterCriteria {
get {
return m_FilterCriteria;
}
set {
m_FilterCriteria = value;

// if there is bound data, apply the select filter now.
ApplyFilter();
}
}

public override void DataBind() {
base.DataBind();

ApplyFilter();
}

protected virtual void ApplyFilter() {
if (m_FilterCriteria != string.Empty && DataSource != null &&
DataSource is DataView) {
DataView dv = DataSource as DataView;

string oldFilter = dv.RowFilter;
dv.RowFilter = m_FilterCriteria;

foreach(DataViewRow dvr in dv) {
object valueVal = dvr.Row[this.DataValueField];

foreach(ListItem item in this.Items) {
if (item.Value.Equals(valueVal)) {
item.Selected = true;
}
}
}

dv.RowFilter = oldFilter;
}
}
}




All times are GMT. The time now is 08:59 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.