Bind result set to Html Div Controls
Hello and thanks for taking a second. I am simply trying to query the Northwind database. The user will give the order number and the name of the employee who took the order and the order date will be displayed in separate html div tags. The page builds but my events do not seem to be running. Any Advice? Below is my .aspx and code behind. Thanks- Jason
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="orderinfoweb.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<b>Put the Order ID in to Find out who took the order and on what date the order
was placed:</b> <INPUT type="text" id="orderID" runat="server"><br>
<br>
<input type="submit" value="search" id="txtsearch" OnShowInfo="ShowInfo" runat="server"><br>
<br>
Order Date<div id="DivOrderDate" runat="server"></div>
<br>
Employee who took order was
<div id="DivEmployee" runat="server"></div>
<br>
<br>
<div id="DivError" runat="server"></div>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace orderinfoweb
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl DivEmployee;
protected System.Web.UI.HtmlControls.HtmlInputButton txtsearch;
protected System.Web.UI.HtmlControls.HtmlGenericControl DivOrderDate;
protected System.Web.UI.HtmlControls.HtmlGenericControl DivError;
protected System.Web.UI.HtmlControls.HtmlInputText orderID;
protected System.Web.UI.HtmlControls.HtmlInputText OrderId ;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ShowInfo(Object sender,EventArgs e)
{
//Declare connection and stored proc to get info
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString="Data Source=Jason;" + "Initial Catalog=Pubs; User ID=sa";
SqlCommand sqlCom = new SqlCommand("usp_retrieve_Order_info");
sqlCom.Connection=myConnection;
sqlCom.CommandType = CommandType.StoredProcedure;
//Add parameters and setting values
sqlCom.Parameters.Add("@OrderId",SqlDbType.Int);
sqlCom.Parameters["@OrderID"].Value =OrderId.Value;
//declare dataAdapter to fill Dataset
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlCom);
//Fill dataSet DS with results set and name the filled table "tblResultSet"
da.Fill(ds, "tblResultSet");
if(ds.Tables["tblResultSet"].Rows.Count > 0)
{
//Fill Divs with with information from Dataset
DivOrderDate.InnerText = ds.Tables["tblResultSet"].Rows[0]["Employee"].ToString();
DivEmployee.InnerText=ds.Tables["tblResultSet"]. Rows[0]["OrderDate"].ToString();
}
else
{
DivError.InnerText="Order was not found";
}
}
}
}
|