Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: PLEASE HELP: Paging, Ranking, Color coding


Message #1 by "Kelly, Patrick" <Patrick.Kelly@H...> on Mon, 8 Apr 2002 11:48:17 -0400

Hi,


I'm new to Asp.net and I'm trying to finish a simple web page that will 
allow the user to look up freight lanes.(See code below)
I'm having a couple of problems and I was hoping that someone could 
please help me out.  I need to have this page done by Friday.

Problem #1

I can't get the paging to work.  I continue to get the error that says I 
must enable custom paging.  I would really perfer to use the built-in 
pagig because I'm using Access queries and not SQL Server stored 
procedures.


Problem #2

I need to have the code highlight a row in the datagrid if one of the 
fields contain a particular type of data.  If the carrier field has 
"core" in it, I would like the entire row to be highlighted red and if 
it contains "base" I would like it be yellow.

Problem #3

Is there a way I can assign rankings to data from within the code.  I 
would like to assign a number ranking from least to greatest and assign 
the same rank to duplicate data.  An example would be if the first lane 
row contained a cost of 500, the second row had 500, and the third had 
600.  I would like to assign the rank of 1 to the first, 1 to the second 
because it is the same, and 2 to the third because it is greater.

Problem #4

How do I send more than one parameters to the stored procedure.


Any help would greatly appreciated!

Thanks
Patrick


C# Code
// created on 4/6/2002 at 10:48 PM
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public class freight_lane : Page{
	protected DataGrid myDataGrid;
=09
	protected void Page_Load(Object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			BindData();
		}
	}
	=09
	protected void BindData()
	{
		OleDbConnection myConnection;
		OleDbCommand myCommand;
		OleDbParameter myParameter;
	=09
	=09
			=09
		myConnection =3D new 
OleDbConnection("Provider=3DMicrosoft.Jet.OLEDB.4.0; Data 
Source=3DC:\\Data\\Consulting\\Raytrans\\WebSite\\Datacontainers\\dbconta
inercorus.mdb;");
		myCommand =3D new OleDbCommand("v_rate_lookup", myConnection);
		myCommand.CommandType =3D CommandType.StoredProcedure;
		myParameter =3D myCommand.Parameters.Add(new OleDbParameter("origin", 
OleDbType.VarChar, 50));
		myParameter.Direction =3D ParameterDirection.Input;
		myParameter.Value =3D "Tuscaloosa";
	=09
		OleDbDataReader myReader =3D null;
	=09
	=09
	=09
	=09
		try
		{
			myConnection.Open();
			myReader =3D myCommand.ExecuteReader();
			myDataGrid.DataSource =3D myReader;
			myDataGrid.DataBind();
		}
		finally
		{
			myConnection.Close();
		}
	}
=09
	protected void PageIndexChanged_OnClick(Object sender, 
DataGridPageChangedEventArgs e)
	=09
		{
			myDataGrid.CurrentPageIndex =3D e.NewPageIndex;
			BindData();
		}
}

ASPX CODE

<%@ Page Inherits=3D"freight_lane" Src=3D"crguide.cs" %>
<html>
	<head>
		<title>Corus Online Routing Guide</title>
			<style rel=3D"raystyle">

				A {text-decoration:none;color:black}
				A:Hover {color:maroon;text-decoration:underline}
				A:Visited {color:red}

			</style>

	</head>

<body>
	<asp:DataGrid
	runat=3D"server"
	id=3D"myDataGrid"
	AutoGenerateColumns=3D"False"
	Gridlines=3D"Both"
	HorizontalAlign=3D"Center"
	Width=3D"100%"
	CellPadding=3D"4"
	CellSpacing=3D"0"
	AllowPaging=3D"True"
	OnPageIndexChanged=3D"PageIndexChanged_OnClick"
	PageSize=3D"20"
	PagerStyle-CssClass=3D"pageLinks"
	PagerStyle-Mode=3D"NextPrev"
	PagerStyle-NextPageText=3D"Next"
	PagerStyle-PrevPageText=3D"Previous"
	PagerStyle-HorizontalAlign=3D"Right"
	PagerStyle-Position=3D"TopAndBottom"
	>
=09
	<columns>
=09
	<asp:BoundColumn
	DataField=3D"OriginCity"
	HeaderText=3D"Origin"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"Destination City"
	HeaderText=3D"Destination"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
	=09
	<asp:BoundColumn
	DataField=3D"costx"
	HeaderText=3D"Cost"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"Carrier"
	HeaderText=3D"Carrier"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	=09
	<asp:BoundColumn
	DataField=3D"Contact"
	HeaderText=3D"Contact"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"Telephone"
	HeaderText=3D"Phone"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"daily_commitment"
	HeaderText=3D"Commitment"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
=09
=09
	</columns>
=09
	</asp:DataGrid>
</body>
</html>



Message #2 by "Kelly, Patrick" <Patrick.Kelly@H...> on Mon, 8 Apr 2002 11:53:35 -0400
Hello


I'm new to Asp.net and I'm trying to finish a simple web page that will 
allow the user to look up freight lanes.(See code below)
I'm having a couple of problems and I was hoping that someone could 
please help me out.  I need to have this page done by Friday.

Problem #1

I can't get the paging to work.  I continue to get the error that says I 
must enable custom paging.  I would really perfer to use the built-in 
pagig because I'm using Access queries and not SQL Server stored 
procedures.


Problem #2

I need to have the code highlight a row in the datagrid if one of the 
fields contain a particular type of data.  If the carrier field has 
"core" in it, I would like the entire row to be highlighted red and if 
it contains "base" I would like it be yellow.

Problem #3

Is there a way I can assign rankings to data from within the code.  I 
would like to assign a number ranking from least to greatest and assign 
the same rank to duplicate data.  An example would be if the first lane 
row contained a cost of 500, the second row had 500, and the third had 
600.  I would like to assign the rank of 1 to the first, 1 to the second 
because it is the same, and 2 to the third because it is greater.

Problem #4

How do I send more than one parameters to the stored procedure.


Any help would greatly appreciated!

Thanks
Patrick


C# Code
// created on 4/6/2002 at 10:48 PM
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public class freight_lane : Page{
	protected DataGrid myDataGrid;
=09
	protected void Page_Load(Object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			BindData();
		}
	}
	=09
	protected void BindData()
	{
		OleDbConnection myConnection;
		OleDbCommand myCommand;
		OleDbParameter myParameter;
	=09
	=09
			=09
		myConnection =3D new 
OleDbConnection("Provider=3DMicrosoft.Jet.OLEDB.4.0; Data 
Source=3DC:\\Data\\Consulting\\Raytrans\\WebSite\\Datacontainers\\dbconta
inercorus.mdb;");
		myCommand =3D new OleDbCommand("v_rate_lookup", myConnection);
		myCommand.CommandType =3D CommandType.StoredProcedure;
		myParameter =3D myCommand.Parameters.Add(new OleDbParameter("origin", 
OleDbType.VarChar, 50));
		myParameter.Direction =3D ParameterDirection.Input;
		myParameter.Value =3D "Tuscaloosa";
	=09
		OleDbDataReader myReader =3D null;
	=09
	=09
	=09
	=09
		try
		{
			myConnection.Open();
			myReader =3D myCommand.ExecuteReader();
			myDataGrid.DataSource =3D myReader;
			myDataGrid.DataBind();
		}
		finally
		{
			myConnection.Close();
		}
	}
=09
	protected void PageIndexChanged_OnClick(Object sender, 
DataGridPageChangedEventArgs e)
	=09
		{
			myDataGrid.CurrentPageIndex =3D e.NewPageIndex;
			BindData();
		}
}

ASPX CODE

<%@ Page Inherits=3D"freight_lane" Src=3D"crguide.cs" %>
<html>
	<head>
		<title>Corus Online Routing Guide</title>
			<style rel=3D"raystyle">

				A {text-decoration:none;color:black}
				A:Hover {color:maroon;text-decoration:underline}
				A:Visited {color:red}

			</style>

	</head>

<body>
	<asp:DataGrid
	runat=3D"server"
	id=3D"myDataGrid"
	AutoGenerateColumns=3D"False"
	Gridlines=3D"Both"
	HorizontalAlign=3D"Center"
	Width=3D"100%"
	CellPadding=3D"4"
	CellSpacing=3D"0"
	AllowPaging=3D"True"
	OnPageIndexChanged=3D"PageIndexChanged_OnClick"
	PageSize=3D"20"
	PagerStyle-CssClass=3D"pageLinks"
	PagerStyle-Mode=3D"NextPrev"
	PagerStyle-NextPageText=3D"Next"
	PagerStyle-PrevPageText=3D"Previous"
	PagerStyle-HorizontalAlign=3D"Right"
	PagerStyle-Position=3D"TopAndBottom"
	>
=09
	<columns>
=09
	<asp:BoundColumn
	DataField=3D"OriginCity"
	HeaderText=3D"Origin"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"Destination City"
	HeaderText=3D"Destination"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
	=09
	<asp:BoundColumn
	DataField=3D"costx"
	HeaderText=3D"Cost"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"Carrier"
	HeaderText=3D"Carrier"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	=09
	<asp:BoundColumn
	DataField=3D"Contact"
	HeaderText=3D"Contact"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"Telephone"
	HeaderText=3D"Phone"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
	<asp:BoundColumn
	DataField=3D"daily_commitment"
	HeaderText=3D"Commitment"
	HeaderStyle-BackColor=3D"maroon"
	HeaderStyle-ForeColor=3D"#FFFFFF"
	HeaderStyle-Font-Size=3D"10"
	HeaderStyle-Font-Bold=3D"true"
	HeaderStyle-Font-Name=3D"Verdana"
=09
	ItemStyle-BackColor=3D"#FFFFFF"
	ItemStyle-ForeColor=3D"#000000"
	ItemStyle-Font-Size=3D"8"
	ItemStyle-Font-Bold=3D"true"
	ItemStyle-Font-Name=3D"Verdana"
	/>
=09
=09
=09
	</columns>
=09
	</asp:DataGrid>
</body>
</html>




  Return to Index