 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 20th, 2004, 02:04 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
DataView.RowFinder()
Hi guys,
I have several drop down lists on a page. When a person selects a value in one or all the boxes, I want a datagrid to show the results. I tryed using the Dataview.RowFilter which is good for using on a dataset but I want it to be dynamic searching the database. I was thinking of using command objects?? Is this possible.
Any ideas
Thanks
Adz - The World is not enough
__________________
Adz - Learning The J2EE Ways.
|
|

April 20th, 2004, 07:04 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Yes it's possible.
You'll need to grab the selected value from the dropdown list(s) and build a database command in the command object based on what has been selected.
|
|

April 21st, 2004, 03:52 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
planoie,
I have 5 drop down lists, the first is a list containing different money bands i.e 0 - 40, 41 - 50 etc.. I want a person to select a value from the drop down list and then submit, this will then show houses within the range of the value chosen. This is my code: -
private void GridDataFiller(object sender, EventArgs e)
{
string strSmokingFilter = Smoking.SelectedItem.Text.ToString();
//The problem with the string below is that it gives a value of 0 - 40 which does no exist in the
//database, how would I get round this??
string strPriceFilter = Payment.SelectedItem.Text.ToString();
string strAreaFilter = ddlAreas.SelectedItem.Text.ToString()
string strFurnished;
lblDescription.Visible = false;
String strConnect = "Provider = Microsoft.Jet.OleDb.4.0; data source = \\\\premfs3\\sites\\premium8\\adnanarab66\\databas e\\House.mdb;";
OleDbConnection objConnection = new OleDbConnection(strConnect);
String strShowDetails = "SELECT * FROM Houses WHERE RentingPrice = ? AND HouseHold = AND OR Smoking = AND Furnished = ?";
OleDbCommand objCommand = new OleDbCommand();
objCommand.Connection = objConnection;
objCommand.CommandType = CommandType.Text;
objCommand.CommandText = strShowDetails;
objCommand.Parameters.Add("RentingPrice", OleDbType.VarChar, 32, "RentingPrice");
objCommand.Parameters.Add("HouseHold", OleDbType.VarChar, 32, "HouseHold");
objCommand.Parameters.Add("Smoking", OleDbType.VarChar, 32, "Smoking");
objCommand.Parameters.Add("Furnished", OleDbType.VarChar, 32, "Furnished");
objCommand.Parameters["RentingPrice"].Value = strPriceFilter;
objCommand.Parameters["HouseHold"].Value = strAreaFilter;
objCommand.Parameters["Smoking"].Value = strSmokingFilter;
objCommand.Parameters["Furnished"].Value = strFurnished;
objConnection.Open();
OleDbDataReader objDataReader = objCommand.ExecuteReader();
if(objDataReader.HasRows)
{
dgHouse.Visible = true;
dgHouse.DataSource = objCommand.ExecuteReader();
dgHouse.DataBind();
}
else
Response.Write("This is doing my head in!");
objConnection.Close();
}
Any ideas??
Adz - The World is not enough
|
|

April 21st, 2004, 04:39 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I see what you are doing. How about this...
You have this selector, the text is a range (0-40, 41-50, etc.), but the VALUE of the option is the MAX (40, 50, etc.) for that range. For the range, you always have some minimum starting point (in this case 0). So you get the current selected value, this is the MAX, and you determine the MIN value by looking at the previous item in the selector or the bottom of the range if there is no previous item.
int intPriceRangeMAX, intPriceRangeMIN;
intPriceRangeMIN = 0; // default range min
intPriceRangeMAX = (int)Payment.SelectedItem.Value;
if(Payment.SelectedItem.ItemIndex > 0){
intPriceRangeMIN = Payment.Items[Payment.SelectedItem.ItemIndex-1].Value + 1;
}
Then you need to structure the query to handle the range values:
String strShowDetails = "SELECT * FROM Houses WHERE RentingPrice BETWEEN ? AND ? AND HouseHold = ? AND OR Smoking = ? AND Furnished = ?";
Hope this gets you off in the right direction.
Peter
-------------------------
Work smarter, not harder
|
|

April 23rd, 2004, 12:07 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Great, thanks man, the thing is, is that you cant convert string to int: -
int PriceRangeMAX = (int)Payment.SelectedItem.Value;
I get an error when I do this: -
Compiler Error Message: CS0030: Cannot convert type 'string' to 'int'
any ideas how to get round this??
Adz - The World is not enough
|
|

April 23rd, 2004, 12:33 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
also the listbox control does not have an itemindex property, man one thing after the other, right now any ideas??
Adz - The World is not enough
|
|

April 23rd, 2004, 12:34 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You should be able to do this convertion.
Did you change the code I gave you? Looks like the int prefix is missing. Check your variables names. Otherwise, I can't imagine what else could be wrong. I work in VB.net more than C# so maybe I got the conversion syntax wrong.
|
|

April 23rd, 2004, 01:08 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Instead of casting to a int directly, use the ToInt32 method of the Convert class:
int PriceRangeMAX = Convert.ToInt32(Payment.SelectedItem.Value);
Of course you may want to wrap this in a Try/Catch block, or make sure Payment.SelectedItem.Value has a valid value before you cast.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |