mercredi 28 juin 2017

Using ASP.NET and C# if statement to show message based on a Checkbox in Access

I'm working on a project where I can show information from an Access Database (Or SQL server I'm using both) on an aspx webpage. I'm working with Visual Studio 2017 and C#.

I'm trying to write an it statement that will state "Your Order has Shipped!" based on if the Shipped row has been marked "Yes". Else, says "Your Order is still in process".

My code so far:

protected void btnSearch_Click(object sender, EventArgs e)
    {
        SqlDataSource1.DataBind();
        string shipped = Convert.ToString(FindControl("Shipped"));
        if (shipped == "Yes") 
        {
            lblShippingMessage.Visible = true;
            lblShippingMessage.Text = "Your Order has shipped!";
        }
        else
        {
            lblShippingMessage.Visible = true;
            lblShippingMessage.Text = "Your Order is still in process.";
        }
    }

My databound items are in a FormView.

    <asp:FormView ID="FormView1" 
     DataSourceID="SqlDataSource1" 
     RunAt="server" Width="500px" 
     OnPageIndexChanging="FormView1_PageIndexChanging">
            <ItemTemplate>
                <h2><%# Eval("Name") %></h2>
                <h5>Order ID: <%# Eval("ID") %></h5>
                Location: <%# Eval("Location") %><br />
                Billing Code: <%# Eval("Billing Code") %><br />
                <br />
                Order Detail: <%# Eval("Order Details") %><br />
                Shipped: <%# Eval("Shipped")%>
            </itemtemplate>                          
        </asp:FormView>

The problem I am having is that every time I load the page, it shows every record as "Your order is still in progress." How do I make the if statement work where it shows the shipped orders as true and the non-shipped items as false?

I've tried setting the row in Access to Yes/No and working with the control as a bool saying if(shipped != 0), but that resulted in the same issue.

Any help would be greatly appreciated. Thanks!

Cassie

Aucun commentaire:

Enregistrer un commentaire