visible=true evaluation

D

duncfair

asp.net 2.0 and language is c#

I need to add a single checkbox on an aspx page based on evaluating
two aspects of the items the customer has placed in the shopping
cart.


The price must be $100 or more and the brand must be a specific
brand.
There may be multiple items in the cart but there can be only one
checkbox. I wrote some code on the codebehind, but it only evaluates
the last item in the cart. How can I evaluate all o the items?


Thanks in advance for any help.
 
M

Michel Racicot

That highly depends on two factors:

-Do you want to do this client side or server side?
-How is your data organized?
 
D

duncfair

Server side solution.

Data is MS SQL server and all datasets, etc. are accessed via stored
procedures.
 
M

Michel Racicot

In that case, maybe the problem resides in the browsing of all item in the
cart.

Paste your stored procedure / SQL Code that must evaluate all items in the
cart and the code that handles the checkbox and maybe we can help you.


Server side solution.

Data is MS SQL server and all datasets, etc. are accessed via stored
procedures.
 
D

duncfair

The stored procedure is fine; SQL programming is my comfort zone.

Here is the code:

-------------------------------------------------------

Dansko_chkbx.Visible = false;
ProductDetailTableAdapter productadp = new
ProductDetailTableAdapter();
DataTable productdatatable =
productadp.GetDanskoProductDetailById(Convert.ToInt32(Orderid.ToString()));
foreach (DataRow ProductDataRow in productdatatable.Rows)
{
DanskoPrice =
Convert.ToDecimal(ProductDataRow["Price"].ToString());
Danskobrandname =
ProductDataRow["BrandName"].ToString();

if ((Danskobrandname.Contains("Dansko")) &&
(DanskoPrice > 100))
{
Dansko_chkbx.Visible = true;
}
else
{
Dansko_chkbx.Visible = false;
}
}

----------------------------------------------
 
M

Michel Racicot

This is the problem ...

You keep changing the visibility of your checkbox at every row because
Dansko_chkbx.Visible is set inside the foreach statement!!! (and it will be
set for every row, so the value it will get at the end will indeed be for
the last iteration of your foreach)





The stored procedure is fine; SQL programming is my comfort zone.

Here is the code:

-------------------------------------------------------

Dansko_chkbx.Visible = false;
ProductDetailTableAdapter productadp = new
ProductDetailTableAdapter();
DataTable productdatatable =
productadp.GetDanskoProductDetailById(Convert.ToInt32(Orderid.ToString()));
foreach (DataRow ProductDataRow in productdatatable.Rows)
{
DanskoPrice =
Convert.ToDecimal(ProductDataRow["Price"].ToString());
Danskobrandname =
ProductDataRow["BrandName"].ToString();

if ((Danskobrandname.Contains("Dansko")) &&
(DanskoPrice > 100))
{
Dansko_chkbx.Visible = true;
}
else
{
Dansko_chkbx.Visible = false;
}
}

----------------------------------------------
 
D

duncfair

OK. So how do I evaluate if any of the rows meet the criteria?

This is the problem ...

You keep changing the visibility of your checkbox at every row because
Dansko_chkbx.Visible is set inside the foreach statement!!!  (and it will be
set for every row, so the value it will get at the end will indeed be for
the last iteration of your foreach)


The stored procedure is fine; SQL programming is my comfort zone.

Here is the code:

-------------------------------------------------------

            Dansko_chkbx.Visible = false;
            ProductDetailTableAdapter productadp = new
ProductDetailTableAdapter();
            DataTable productdatatable =
productadp.GetDanskoProductDetailById(Convert.ToInt32(Orderid.ToString()));
            foreach (DataRow ProductDataRow in productdatatable.Rows)
            {
                DanskoPrice =
Convert.ToDecimal(ProductDataRow["Price"].ToString());
                Danskobrandname =
ProductDataRow["BrandName"].ToString();

                if ((Danskobrandname.Contains("Dansko"))  &&
(DanskoPrice > 100))
{
Dansko_chkbx.Visible = true;}

else
{
Dansko_chkbx.Visible = false;}

            }

----------------------------------------------

In that case, maybe the problem resides in the browsing of all item in the
cart.
Paste your stored procedure / SQL Code that must evaluate all items in the
cart and the code that handles the checkbox and maybe we can help you.
"duncfair" <[email protected]> wrote in message
Server side solution.
Data is MS SQL server and all datasets, etc. are accessed via stored
procedures.
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
M

Michel Racicot

Sorry to tell you that but this is beginner's stuff... I highly suggest that
you try to understand what you're doing a little better before.

There is several way to achieve the result.

Since it can be for a school project and I don't want to give the answer
crudely, here comes a hint for one possible solution:

You can use a variable.

Another hint for another possible solution:

When if ((Danskobrandname.Contains("Dansko")) && (DanskoPrice > 100)) is
true, you don't even have to evaluate the reminder items. It saves some
iterations...

Good luck.


OK. So how do I evaluate if any of the rows meet the criteria?

This is the problem ...

You keep changing the visibility of your checkbox at every row because
Dansko_chkbx.Visible is set inside the foreach statement!!! (and it will
be
set for every row, so the value it will get at the end will indeed be for
the last iteration of your foreach)


The stored procedure is fine; SQL programming is my comfort zone.

Here is the code:

-------------------------------------------------------

Dansko_chkbx.Visible = false;
ProductDetailTableAdapter productadp = new
ProductDetailTableAdapter();
DataTable productdatatable =
productadp.GetDanskoProductDetailById(Convert.ToInt32(Orderid.ToString()));
foreach (DataRow ProductDataRow in productdatatable.Rows)
{
DanskoPrice =
Convert.ToDecimal(ProductDataRow["Price"].ToString());
Danskobrandname =
ProductDataRow["BrandName"].ToString();

if ((Danskobrandname.Contains("Dansko")) &&
(DanskoPrice > 100))
{
Dansko_chkbx.Visible = true;}

else
{
Dansko_chkbx.Visible = false;}

}

----------------------------------------------

In that case, maybe the problem resides in the browsing of all item in
the
cart.
Paste your stored procedure / SQL Code that must evaluate all items in
the
cart and the code that handles the checkbox and maybe we can help you.
"duncfair" <[email protected]> wrote in message
Server side solution.
Data is MS SQL server and all datasets, etc. are accessed via stored
procedures.
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
D

duncfair

Thanks! I will end the loop when I get a 'true'.

Unfortunately, it's not a school project. I am a sql db programmer
struggling through web development tasks.

Sorry to tell you that but this is beginner's stuff... I highly suggest that
you try to understand what you're doing a little better before.

There is several way to achieve the result.

Since it can be for a school project and I don't want to give the answer
crudely, here comes a hint for one possible solution:

You can use a variable.

Another hint for another possible solution:

When if ((Danskobrandname.Contains("Dansko")) && (DanskoPrice > 100)) is
true, you don't even have to evaluate the reminder items.  It saves some
iterations...

Good luck.


OK. So how do I evaluate if any of the rows meet the criteria?

This is the problem ...
You keep changing the visibility of your checkbox at every row because
Dansko_chkbx.Visible is set inside the foreach statement!!! (and it will
be
set for every row, so the value it will get at the end will indeed be for
the last iteration of your foreach)
"duncfair" <[email protected]> wrote in message
The stored procedure is fine; SQL programming is my comfort zone.
Here is the code:
-------------------------------------------------------

Dansko_chkbx.Visible = false;
ProductDetailTableAdapter productadp = new
ProductDetailTableAdapter();
DataTable productdatatable =
productadp.GetDanskoProductDetailById(Convert.ToInt32(Orderid.ToString()));
foreach (DataRow ProductDataRow in productdatatable.Rows)
{
DanskoPrice =
Convert.ToDecimal(ProductDataRow["Price"].ToString());
Danskobrandname =
ProductDataRow["BrandName"].ToString();
if ((Danskobrandname.Contains("Dansko")) &&
(DanskoPrice > 100))
{
Dansko_chkbx.Visible = true;}
else
{
Dansko_chkbx.Visible = false;}
- Show quoted text -- Hide quoted text -

- Show quoted text -
 

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

Top