select *

  • Thread starter Thread starter Mr. SweatyFinger
  • Start date Start date
M

Mr. SweatyFinger

I have a gridview and a sqlserver datasource.
I also have a dropdownlist of countries.

The gridview displays a bunch of crap about whatever country is selected in
the countries dropdownlist

I want to add a selection "ALL COUNTRIES"

but what would its value be?


I mean, did they leave this simple operation of their plans???

I need a value for "all"

how about ^ or && or $$ or anything dammit

select all where idno=***
anything.

Has no one come across this??
 
as a general rule, repeating the question and being rude to people who are
genuinely trying to help will not get you better answers.

look up the DropDownList web control in the SDK and you will see that it has
a property called AppendDataBoundItems. learn how to use it there.

i think you are going about your problem the wrong way. you are trying to
add a filter for 'ALL COUNTRIES', but this is a contradiction because you
don't need a filter when you want to view all the records. for example, try
this pseudocode:

protected void CountriesDDL_SelectedIndexChanged(.....)
{
string sql = "select * from TableWhatever"; // get all records
if(this.CountriesDDL.SelectedValue != 0) // user selected a specific
country, add a filter 'where' clause
sql += String.Format(" where country = '{0}'",
this.CountriesDDL.SelectedValue);

DataSet ds = // write some code to execute the query and get a dataset,
however you want
this.GridView1.DataSource = ds.;
this.GridView1.DataBind();
}

if you're smart you will use a parameterised sql query instead of a
string-based sql query like i have posted above. i did it this way for
simplicity. alternatively, your sql query could select all the records
anyway, and then create a DataView on the dataset, filtered to whatever the
user selected, if they selected a country.
if you use david wiers suggestion of AppendDataBoundItems, and you add in an
item with a value of 0 for 'All Countries' then it should work.

tim
 
Back
Top