Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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
 
Old December 22nd, 2008, 02:31 AM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default C# Syntax problem

I'd like to make a change to an existing ASP.NET 2.0 commerce site so that certain products are flagged with a warning label. The website's product details page already uses such boolean-triggered flags for other product information, so I have copied the existing format to add a path for this additional boolean field from the .cs page back through the DAL, the stored procedure, and the database's products table.

I have the new flag's asp:Image tag in place on the .aspx page, but I am not sure where to place the switching code on the .cs page so as not to create a compile or runtime error.

Here is a cut-down version of the Product Detail page's .cs file showing what I hope are the relevant parts (a copy of the full .cs page is here):
Code:
namespace MySite
{
    public partial class productdetail : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Image Image1;
                //[a series of WebControl declarations here]
        protected System.Web.UI.WebControls.Image imgNew;
                //["imgNew" is one of the existing boolean flags]

public void BindTheData()
    {
        .... code ....

            if (!errorFlg)
            {
                if (dataset.Tables[0].Rows.Count > 0)
                {
                DataRow tr = dataset.Tables[0].Rows[0];
                imgProduct.ImageUrl = "images/products/" +tr["IMAGEFILE_NM"].ToString();
                litName.Text = "<h3 id='detName'>" + tr["NAME"].ToString() +"</h3>";
                    //Create the grades label
                    string from_grade = tr["FROM_GRADE"].ToString();
                    string to_grade = tr["TO_GRADE"].ToString();
                    if (from_grade.Length > 0 && to_grade.Length > 0)
                    {
                        lbGrades.Text = "Grades "+ from_grade + " - " + to_grade;
                    }
                    if (from_grade == to_grade)
                    {
                        lbGrades.Text = "Grade "+ from_grade;
                    }
                    if (from_grade.Length > 0 && to_grade.Length == 0)
                    {
                        lbGrades.Text = "Grades "+ from_grade + "+";
                    }
                    if (from_grade.Length == 0 && to_grade.Length == 0)
                    {
                        lbGrades.Text = "";
                    }

                    lbContent.Text = tr["NSES_NM"].ToString();
                    lbDescription.Text = tr["DESCRIPTION"].ToString();

            
                      //Remove these icons from the ProductLine1/ProductLine11 products

                    string topic_id = tr["TOPIC_CD"].ToString();
                    if (topic_id != "1" || topic_id != "11")
                    {
                        //Format the image icons representing award, resource

                        string awardFlg = tr["award_flg"].ToString();
                        string ResourceFlg = tr["resource_flg"].ToString();
                        if (awardFlg == "1")
                        {
                            imgAward.Visible = true;
                        }
                        if (ResourceFlg == "1")
                        {
                            imgResource.Visible = true;
                        }

                    }
.....code.....
}
I want the flags to apply to all products, not just the "if (topic_id != "1" || topic_id != "11"" ones mentioned above. I have tried to insert a copy of the code for one of the preexisting flags:
Code:
string MyNewFlg = tr["my_new_flg"].ToString();
if (MyNewFlg == "1")
    {
    imgMyNewFlag.Visible = true;
    }
If I place the new flag code either inside or outside of the topic_id exclusion the solution builds OK, I get the following runtime error:
Quote:
Column 'my_new_flg' does not belong to table Table...
Exception Details: System.ArgumentException: Column 'my_new_flg' does not belong to table Table.
Is the code I am imitating creating some sort of dynamic table, and that is causing the screwup? Should I be using something like
Code:
if (productTable.MyNewFlagColumn > 0)
            {
               MyNewFlag.Visible = true;
            }
?
Thanks for any advice.
 
Old December 23rd, 2008, 01:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Aren't the columns that are working not just a part of a SQL clause that is used to fill the DataSet / DataTable in the first place?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with syntax MarkMingLuy ASP.NET 1.0 and 1.1 Basics 1 November 30th, 2006 07:42 AM
syntax problem with SQL nancy SQL Server 2000 4 May 6th, 2005 12:56 PM
Syntax Problem Please i need your help haron_Master VB Databases Basics 4 February 2nd, 2005 01:56 PM
xpath syntax problem nrane26 XSLT 1 January 22nd, 2005 01:25 PM
Query syntax problem mateenmohd Access 2 October 12th, 2004 11:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.