最近写了一个图书馆的网站,,可是在显示图书信息时,图书的表格却未显示出来,,希望各位高手帮帮忙哈using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class bookInfoSearch : System.Web.UI.Page
{
static string sql = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userName"] != null) //判断管理员是否登录
{
if (!getSet()) //判断是否拥有权限 Response.Write("<script>alert('您没有此权限');location='index.aspx';</script>");
else
bindBookType();
}
else
{
Response.Redirect("entry.aspx"); //返回到登录页面
}
}
public bool getSet()
{
string userName = Session["userName"].ToString(); //获取管理员登录名
string sql = "select * from tb_admSet where userName='" + userName + "'";
SqlDataReader sdr = dataOperate.getRow(sql);
sdr.Read(); //读取一条记录
return Convert.ToBoolean(sdr["systemSearch"]); //返回是否拥有权限
}
//自定义方法绑定图书类型
public void bindBookType()
{
string typeSql = "select * from tb_bookType";
ddlBookType.DataSource = dataOperate.getDataset(typeSql, "tb_bookType");
ddlBookType.DataTextField = "typeName";
ddlBookType.DataValueField = "typeID";
ddlBookType.DataBind();
}
protected void ddlCondition_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlCondition.SelectedValue.Trim() == "bookType")
{
txtKey.Visible = false;
ddlBookType.Visible = true;
RequiredFieldValidator1.Visible = false;
bindBookType();
}
else
{
txtKey.Visible = true;
RequiredFieldValidator1.Visible = true;
ddlBookType.Visible = false;
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
string Condition = ddlCondition.Text;
string key = "";
if (ddlBookType.Visible)
{
key = ddlBookType.SelectedValue;
}
else
key = txtKey.Text;
sql = "select * from tb_bookInfo where " + Condition + " like '%" + key + "%'";
bindBookInfo(sql);
txtKey.Text = "";
}
public void bindBookInfo(string sql)
{
gvBookInfo.DataSource = dataOperate.getDataset(sql, "tb_bookInfo");
gvBookInfo.DataBind();
}
protected void gvBookInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ //设置图书类型
string bookType = e.Row.Cells[2].Text.ToString(); //获取图书类型编号
string typeSql = "select * from tb_bookType where TypeID=" + bookType;
SqlDataReader typeSdr = dataOperate.getRow(typeSql);
typeSdr.Read(); //读取一条记录
e.Row.Cells[2].Text = typeSdr["typeName"].ToString();
//设置书架
string bookcase = e.Row.Cells[3].Text.ToString(); //获取书架编号
string caseSql = "select * from tb_bookcase where bookcaseID=" + bookcase;
SqlDataReader caseSdr = dataOperate.getRow(caseSql);
caseSdr.Read(); //读取一条记录
e.Row.Cells[3].Text = caseSdr["bookcaseName"].ToString();
}
}
protected void gvBookInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvBookInfo.PageIndex = e.NewPageIndex;
bindBookInfo(sql);
}
}界面如下:
我想要的界面是这样的而在实际网站运行中,却得到了这样的界面却没中间的表格 不知是为何
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class bookInfoSearch : System.Web.UI.Page
{
static string sql = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userName"] != null) //判断管理员是否登录
{
if (!getSet()) //判断是否拥有权限 Response.Write("<script>alert('您没有此权限');location='index.aspx';</script>");
else
bindBookType();
}
else
{
Response.Redirect("entry.aspx"); //返回到登录页面
}
}
public bool getSet()
{
string userName = Session["userName"].ToString(); //获取管理员登录名
string sql = "select * from tb_admSet where userName='" + userName + "'";
SqlDataReader sdr = dataOperate.getRow(sql);
sdr.Read(); //读取一条记录
return Convert.ToBoolean(sdr["systemSearch"]); //返回是否拥有权限
}
//自定义方法绑定图书类型
public void bindBookType()
{
string typeSql = "select * from tb_bookType";
ddlBookType.DataSource = dataOperate.getDataset(typeSql, "tb_bookType");
ddlBookType.DataTextField = "typeName";
ddlBookType.DataValueField = "typeID";
ddlBookType.DataBind();
}
protected void ddlCondition_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlCondition.SelectedValue.Trim() == "bookType")
{
txtKey.Visible = false;
ddlBookType.Visible = true;
RequiredFieldValidator1.Visible = false;
bindBookType();
}
else
{
txtKey.Visible = true;
RequiredFieldValidator1.Visible = true;
ddlBookType.Visible = false;
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
string Condition = ddlCondition.Text;
string key = "";
if (ddlBookType.Visible)
{
key = ddlBookType.SelectedValue;
}
else
key = txtKey.Text;
sql = "select * from tb_bookInfo where " + Condition + " like '%" + key + "%'";
bindBookInfo(sql);
txtKey.Text = "";
}
public void bindBookInfo(string sql)
{
gvBookInfo.DataSource = dataOperate.getDataset(sql, "tb_bookInfo");
gvBookInfo.DataBind();
}
protected void gvBookInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ //设置图书类型
string bookType = e.Row.Cells[2].Text.ToString(); //获取图书类型编号
string typeSql = "select * from tb_bookType where TypeID=" + bookType;
SqlDataReader typeSdr = dataOperate.getRow(typeSql);
typeSdr.Read(); //读取一条记录
e.Row.Cells[2].Text = typeSdr["typeName"].ToString();
//设置书架
string bookcase = e.Row.Cells[3].Text.ToString(); //获取书架编号
string caseSql = "select * from tb_bookcase where bookcaseID=" + bookcase;
SqlDataReader caseSdr = dataOperate.getRow(caseSql);
caseSdr.Read(); //读取一条记录
e.Row.Cells[3].Text = caseSdr["bookcaseName"].ToString();
}
}
protected void gvBookInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvBookInfo.PageIndex = e.NewPageIndex;
bindBookInfo(sql);
}
}界面如下:
我想要的界面是这样的而在实际网站运行中,却得到了这样的界面却没中间的表格 不知是为何
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货