objectdatasource filter.

S

Stephanie

I have a page with 2 drop down list, each set to autopostback = true. I have
a gridview bound to an objectdatasource which is connected (what would be
the right term here?) to a tableadapter in a dataset.

I have an event for each drop down to add a blank entry to the drop down:
protected void ddMediumId_DataBound(object sender, EventArgs e)

{

ddMediumId.Items.Insert(0, ""); <-- little side question, how do I make
the value of this item zero?

}

protected void ddStatusList_DataBound(object sender, EventArgs e)

{

ddStatusList.Items.Insert(0, "");

}

On page load, I am trying to filter the objectdatasource data based on the
selection from the drop down lists. I am testing first with only one of the
drop downs.



protected void Page_Load(object sender, EventArgs e)

{

if (Page.IsPostBack)

{



string sMediumId;

string sStatusId;



sMediumId = ddMediumId.SelectedValue;

sStatusId = ddStatusList.SelectedValue;



/// do something to get the code to filter the ol crapola

lblTest.Text = "" + sMediumId + " - " + sStatusId;

if (!sMediumId.Equals(""))

{

dbviewArtworkList.FilterExpression = "meduimId='{" + sMediumId +"}'";

}

}

}

I got the syntax for the FilterExpression string from an example on the web.
I am not certain it is correct. So this code runs, executes properly when
the mediumId has been selected. But no filter on the data occurs. My guess
is one of the following:

- I need some kind of method for yes, please rebind me.
- I need to put it in a more appropriate event whose timing regarding the
creation of the objectdatasource would make this work... I tried the
onfiltering event, but that did not work either... Nothing causedthe
filtering to fire... That makes sense. I tried the onselecting event, that
fired on the first page load but not on postback. (That makes no sense to
me.,,)

Anyway, can anyone please give me a nudge as to what I am missing. I am sure
this is really straightforward and I am having brain freeze. Thanks!
 
R

Rain

The way you have explained it is a little confusing to me. I think what
maybe happing is that your binding is taking place after the filter
expression because you are using wizard style controls ????

You can beakpoint this line and look at the datasource and see if the filter
expression is taking effect on its produced output. If so, then databinding
is taking place later and rebinding.

If this is not the case, then you can call the .DataBind() method of the
object to rebind it with the parameters you have given it. OR it may be you
are binding your datasource to the unfiltered view of theData control.

Personally, I hate using controls like sql datasource. I know they make
things simple in a ms wizard like way, but its far more satisfying to me to
wite the code natively and have full control over where and when the binding
takes place.

HTH
 
S

Stephanie

Rain said:
The way you have explained it is a little confusing to me. I think
what maybe happing is that your binding is taking place after the
filter expression because you are using wizard style controls ????

You can beakpoint this line and look at the datasource and see if the
filter expression is taking effect on its produced output. If so,
then databinding is taking place later and rebinding.

If this is not the case, then you can call the .DataBind() method of
the object to rebind it with the parameters you have given it. OR it
may be you are binding your datasource to the unfiltered view of
theData control.
Personally, I hate using controls like sql datasource. I know they
make things simple in a ms wizard like way, but its far more
satisfying to me to wite the code natively and have full control over
where and when the binding takes place.


Me too. But I still want to learn how they work together. Thanks.
 
S

Stephanie

Rain said:
The way you have explained it is a little confusing to me. I think
what maybe happing is that your binding is taking place after the
filter expression because you are using wizard style controls ????

You can beakpoint this line and look at the datasource and see if the
filter expression is taking effect on its produced output. If so,
then databinding is taking place later and rebinding.

If this is not the case, then you can call the .DataBind() method of
the object to rebind it with the parameters you have given it. OR it
may be you are binding your datasource to the unfiltered view of
theData control.


I have a view defined in SQL Server Express which has no where clause
initially. When the page is first loaded, I load the whole shooting match.
Is this relevant?
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top