这个demo实现了两个功能 下拉菜单 和 gridview分页
运行环境 visual studio2008 oracle9i
这个网站下载了几种菜单样式 http://www.javascript-menu.com/docs/
运行了一下 感觉挺不错的 分析菜单结构 主要是页面new一个对像调用两个js文件 生成菜单
我使用的是一个website(站点结构图可以去我的像册看一下) 可以使用webapplication(有命名空间 找事件代理方便)
具体demo代码如下 欢迎拍砖 (粘出来直接放到指定名称的文件中 就能用 已测试)
1.default 页面主要是登录功能
2.登录成功后跳转到listpage页面
default.aspx页面
[code]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function CheckInput() {
var username = document.getElementById('txtuserName');
var password = document.getElementById('txtpassWord');
if (username.value != '' && password.value != '') {
return true;
}
return false;
}
function Redirect() {
window.open('RegisterPage.aspx', 'RegisterPage', 'fullscreen=2,top=30,left=30,scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no,location=no,height=310,width=660,');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="tab">
<tr>
<td colspan="2">
<label id="lablogo" >登录</label>
</td>
</tr>
<tr>
<td>
<asp:Label id="lbluserName" runat="server" Text="用户名"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtuserName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblpassWord" runat="server" Text="密码" ></asp:Label>
</td>
<td>
<asp:TextBox ID="txtpassWord" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td align="right">
<asp:Button ID="btnlogin" runat="server" Text="登录" onclick="btnlogin_Click" OnClientClick="return CheckInput();"/>
<input type="button" id="btnregiste" onclick="Redirect();" value="注册"/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
[/code]
default.aspx.cs页面
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyApplication;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnlogin_Click(object sender, EventArgs e)
{
string userName = txtuserName.Text;
string password = txtpassWord.Text;
if (userName.Trim() != string.Empty && password.Trim() != string.Empty)
{
//验证用户合法性 页面跳转
BLLLogic bll = new BLLLogic();
bool isPass = false;
try
{
isPass = bll.CheckUserNameAndPassword(userName, password);
}
catch
{
Comm.Show(this, "数据库连接问题", "库连接失败");
return;
}
if (isPass)
{
Response.Redirect("listPage.aspx");
}
else
{
Comm.Show(this, "输入错误", "用户名或密码输入错误!");
}
}
else
{
Comm.Show(this,"输入错误","用户名和密码不能为空!");
}
}
}
[/code]
listpage.aspsx页面
[code]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="listPage.aspx.cs" Inherits="listPage" %>
<%@ Register src="changePage.ascx" tagname="changePage" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" href="menu.css">
<script language="JavaScript" src="menu.js"></script>
<!-- items structure. menu hierarchy and links are stored there -->
<script language="JavaScript" src="menu_items.js"></script>
<!-- files with geometry and styles structures -->
<script language="JavaScript" src="menu_tpl.js"></script>
</head>
<body style="">
<form id="form1" runat="server">
<div>
<table>
<tr>
<td colspan="4" onmouseover="" onmouseout="">
<div id="divmenu" runat="server">
</div>
</td>
</tr>
<tr>
<td colspan="4">
<label id="lbllogon" >数据库对像信息</label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblSchema" runat="server" Text="对像模式:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlSchema" runat="server" Width="200px"></asp:DropDownList>
</td>
<td>
<asp:Label ID="lblType" runat="server" Text="对像类型:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlType" runat="server" Width="200px"></asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblName" runat="server" Text="对像名称:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtName" runat="server" Width="200px"></asp:TextBox>
</td>
<td>
</td>
<td align="right">
<asp:Button ID ="btnSearch" runat="server" Text="查询"
onclick="btnSearch_Click" />
</td>
</tr>
<tr>
<td colspan="4">
<asp:DataGrid ID="dgrObjectInfo" runat="server" AutoGenerateColumns="false" PagerStyle-Mode="NumericPages"
PagerStyle-PageButtonCount="5" AllowCustomPaging="True">
<PagerStyle Mode="NumericPages" PageButtonCount="5"></PagerStyle>
<Columns>
<asp:ButtonColumn DataTextField="OBJECT_NAME" HeaderText="对像名称"></asp:ButtonColumn>
<asp:BoundColumn DataField="OWNER" HeaderText ="用户名称"></asp:BoundColumn>
<asp:BoundColumn DataField="OBJECT_TYPE" HeaderText="对像类型"></asp:BoundColumn>
<asp:BoundColumn DataField="STATUS" HeaderText="状态"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED" HeaderText="创建日期" DataFormatString="{0:yyyy-mm-dd}">
<itemstyle horizontalalign="Center" />
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</td>
</tr>
<tr>
<td>
<uc1:changePage ID="cpControl" runat="server" />
</td>
</tr>
</table>
</div>
</form>
<%--<script language='JavaScript'> new menu(MENU_ITEMS, MENU_TPL);</script>--%>
</body>
</html>
[/code]
listpage.aspx.cs页面
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyApplication;
public partial class listPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cpControl.XiaoClick += SearchResultbyCondition;
if (!IsPostBack)
{
int count = 0;
try
{
count = int.Parse(System.Configuration.ConfigurationManager.AppSettings["PageCount"]); //从配制文件中取得列表显示数据项数
}
catch (Exception ex)
{
Comm.Show(this, "配制错误", "配置文件[pagecount]出错!");
}
LoadDDLInfo();
BindGridView(1, count, "0", "0", "0");
cpControl.CurrentPage = "1";
if (new BLLLogic().CheckExistFile("MENU_ITEMS.js"))
{
string script = "<script language='JavaScript'>new menu (MENU_ITEMS, MENU_TPL);</script>";
ClientScript.RegisterClientScriptBlock(typeof(System.String), "key", script, false);
}
else
{
//生成js脚本
new BLLLogic().WriteMenuJS();
string script = "new menu (MENU_ITEMS, MENU_TPL);";
ClientScript.RegisterClientScriptBlock(typeof(System.String), "key", script, true);
}
}
}
/// <summary>
/// 获取用户信息
/// </summary>
/// <param name="currPage"> 当前页数</param>
/// <param name="count"> 每页显示页数</param>
/// <param name="userSchema"> 要查询的用户名称</param>
/// <param name="userType"> 要查询的用户类型</param>
/// <param name="objectName"> 要查询的对像名称</param>
/// <returns> 获取用户信息</returns>
public DataSet GetUserOjbectSchemaInfo(int currPage, int count, string userSchema, string userType, string objectName)
{
return new BLLLogic().GetUserOjbectSchemaInfo(currPage, count, userSchema, userType, objectName);
}
public void BindGridView(int currPage, int recount, string userSchema, string userType, string objectName)
{
DataSet ds = GetUserOjbectSchemaInfo(currPage, recount, userSchema, userType, objectName);
if (!Comm.CheckDatasetISNULL(ds))
{
dgrObjectInfo.DataSource = ds;
dgrObjectInfo.DataBind();
cpControl.PageCount = ds.Tables[0].Rows[0]["pageCount"].ToString();
cpControl.CurrentPage = currPage.ToString();
}
else
{
dgrObjectInfo.DataSource = new DataSet();
dgrObjectInfo.DataBind();
}
}
//加载所有下拉列表
public void LoadDDLInfo()
{
LoadSchema();
LoadType();
}
public void LoadSchema()
{
DataSet ds = new BLLLogic().GetSchemaInfo();
if (!Comm.CheckDatasetISNULL(ds))
{
ddlSchema.DataSource = ds;
ddlSchema.DataValueField = "User_ID";
ddlSchema.DataTextField = "UserName";
ddlSchema.DataBind();
}
else
{
ddlSchema.DataSource = new DataSet();
ddlSchema.DataBind();
}
}
public void LoadType()
{
DataSet ds = new BLLLogic().GetTypeInfo();
if (!Comm.CheckDatasetISNULL(ds))
{
ddlType.DataSource = ds;
ddlType.DataValueField = "Type_ID";
ddlType.DataTextField = "Type_Name";
ddlType.DataBind();
}
else
{
ddlType.DataSource = new DataSet();
ddlType.DataBind();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
SearchResultbyCondition(1);
if (cpControl.Handler != null)
{
cpControl.Handler();
}
}
public void SearchResultbyCondition(int currentCount)
{
string userSchema = Comm.ReturnZoreWhenempty(ddlSchema.SelectedItem.Text.Trim());
string objectName = Comm.ReturnZoreWhenempty(txtName.Text.Trim());
string userType = Comm.ReturnZoreWhenempty(ddlType.SelectedItem.Value.Trim());
int count = int.Parse(System.Configuration.ConfigurationManager.AppSettings["PageCount"]); //从配制文件中取得列表显示数据项数
BindGridView(currentCount, count, userSchema, userType, objectName);
}
protected void dgrObjectInfo_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "ObjectName")
{
int index = Convert.ToInt32(e.CommandArgument);
string objectName = dgrObjectInfo.Items[index].Cells[0].Text;
}
}
}
[/code]