关于使用C#中web.config来进行权限限制,好麻烦!
使用repeater控件显示数据库数据
使用dropDownList 下拉数据
使用repeater控件,其他文章如cookies,session讲的很细
好多Oracle知识以及Linux脚本结合
关于发布,没看明白,先留着
图片在文档上数据库设计这一块,可以加入数据库实现
将数据库模型图贴上去。1、在你加载原始数据到文本框的方法里面加上
if(!IsPostBack)
{
//此处加载文本框原始数据,并且只有再第一次加载页面的时候才改变textbox的值
}
意思是只有再页面首次加载的时候才加载文本框的值,如果是回传,则不加载
2、更新的方法里面加上
if(IsPostBack){
//此处写更新方法
}
意思是,当是页面回传的时候,更新文本框的值,其实这个加不加无所谓。现有时间,在之后的addtime中使用
DateTime.Now.ToString(); 在后台页面写逻辑代码,返回字符串

public void Handler(string str)
{
if (str.Length > 5000)
{
Response.Write("<div title='" + str + "'>" + str.Substring(0, 1000) + "</div>");
}
else
{
Response.Write(str);
} }
// or public string Handler(string str)
{
if (str.Length > 5000)
{
return "<div title='" + str + "'>" + str.Substring(0, 1000) + "</div>";
}
else
{
return str;
}
}
前台调用:
<%# Handler(Eval("Field").ToString()) %> 注意Eval还可以绑定对象.属性 如:<%# Handler(Eval("User.Name").ToString()) %>
二、动态创建表头

在GridView的RowCreated事件中,添加以下代码:

//设计表头
protected void SmartGridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
TableCellCollection header = e.Row.Cells;
header.Clear();

string headtxt = "名称</th>";
headtxt += "<th colspan='4'>汇总</th>"; //跨四列

headtxt += "<th>星期一</th><th>星期二</th><th>星期三</th><th>星期四</th>";
headtxt = headtxt.Substring(0, headtxt.Length - 5); //移除掉最后一个</th>

TableHeaderCell cell = new TableHeaderCell();
cell.Attributes.Add("rowspan", "2"); //跨两行
cell.Text = (headtxt);
header.Add(cell);

}
}最后的显示的GridView表头结果


private void Page_Load(object sender, System.EventArgs e) {


if (!IsPostBack) {

DataSet dset = new DataSet();

string conn = "server=(local);Initial Catalog=Northwind;UID=ctester;PWD=password";

string qry = "SELECT firstname, lastname, address, city, region, postalcode,

homephone FROM employees";

SqlDataAdapter sda = new SqlDataAdapter(qry, conn);

sda.Fill(dset);

Repeater1.DataSource = dset.Tables[0].DefaultView;

Repeater1.DataBind();

} }

</script></head>

<body MS_POSITIONING="GridLayout" bgColor="#00cc99">

<form id="Form1" method="post" runat="server">

<div >

<%# ((DataView)Repeater1.DataSource).Count + " employees found." %>

</div></FooterTemplate>

</asp:Repeater></div></form></body></html>


只从数据库中读取指定的列值,在之后可以将想要的列的值组成一组字符串,用label显示
string userid="";假设你取到userid;
SQLConnection con = new SQLConnection("连接字符串");
con.Open();
SQLCommand com = new SQLCommand("select * from biao where userid = '"+userid+"'",con);
SQLDataReader dr = com.ExcuteReader();
if(dr.Read())
{
变量1=dr["列名"].ToString();
变量2=dr["列名"].ToString();
} string ConString = ConfigurationManager.ConnectionStrings["DemoConnectionString"].ConnectionString.ToString();
protected void Page_Load(object sender, EventArgs e)
{
string sql = "select username,password,sex from TestDB wher id=1";//sql语句
SqlConnection con = new SqlConnection(ConString);
con.Open();//打开连接
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox1.Text = dr["username"].ToString();//texbox1的值
TextBox2.Text= dr["password"].ToString();//texbox2的值
TextBox3.Text= dr["sex"].ToString();//texbox3的值
}
con.Close();//关闭连接
}
在界面中放入一个CheckBoxHttpCookie loginCookie = new HttpCookie("name");
HttpCookie loginCookiepwd = new HttpCookie("pwd");
if (CheckBox1.Checked == true)//判断是否要保存密码
{//将用户名和密码保存到Cookie中
loginCookie.Values.Add("uname", txtUser.Text.Trim());
loginCookiepwd.Values.Add("upwd", txtPwd.Text.Trim());
Response.Cookies.Add(loginCookie);
Response.Cookies.Add(loginCookiepwd); //设置用户名和密码保存的期限
loginCookiepwd.Expires = DateTime.Now.AddYears(1);
loginCookie.Expires = DateTime.Now.AddYears(1);
}登录框-->输入帐号密码----验证页【查询数据库,如果允许登录 session("username")=rs("username") 】
这个session是在服务器的内存里边,只要浏览器不关,或者设定的失效时间没到,就一直在内存里边。
你在以后的每个需要的页面添加response.write(session("username")),如果session为空是不显示的
加入在你登陆验证的方法中,在获取成功登陆哪步,加上Session["UserName"]=UserName;这个当前的用户名就存到名为UserNmae中去了,然后再登陆成功页面后,
在把它取出来,加入你使用<Lable>接收并显示,就如:<asp:Lable id="LoginIn" runat="server"></Lable> 在.CS文件里,LoginIn.text=Session["UserName"] 即可<%=Eval(session("user"))%>
可以把登录的用户身份存入session["user"]="管理员or普通用户"
然后在Page_Load()中判断用户身份根据身份再把后台管理页做显示或隐藏处理//byte[] buffByle = (Byte[])prtb.Rows[0]["sPicture"];//把数据库中图片的二进制数据转换一个byte数组
//int filelength = buffByle.Length;//获得数组的长度
创建在服务器上对应虚拟路径的物理路径
string myUrl = HttpContext.Current.Server.MapPath(this.Request.ApplicationPath) + "TempDownLoad";
//System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath("TempDownLoad"));
//if (file.Exists)
//{
// file.Delete();
//}
//string myUrl = Server.MapPath("TempDownLoad"); 创建文件流
//FileStream fs = new FileStream(myUrl, FileMode.OpenOrCreate);
//BinaryWriter w = new BinaryWriter(fs);//以二进制的形式将基元内写入流
//w.BaseStream.Write(buffByle, 0, filelength);//把数据库中的图片二进制添加到BinaryWriter
//w.Flush(); //w.Close();
//Image1.ImageUrl = "~/TempDownLoad";
主要有一下几个知识点:

1.显示序号列<%# Container.ItemIndex +1 %>

这个是在不分页的情况下,如果分页的话第N页都是从1~pagesize显示的,不会接着上一页的序号显示。所以要在后台另构造序号列column来解决

2.获取选中行的主键

repeater控件没有DataKeyNames属性,所以这里要放一个Label或者HiddenField来绑定主键ID

3.分页

repeater控件没有自己的分页属性,所以要完全自己来定义分页代码。这里每次只装在一页数据。

4.没有数据的时候显示表头 Visible="<%#Repeater1.Items.Count==0 %>"




[html] view plaincopy
01.<!--前端代码:-->
02.<body>
03.<form id="form1" runat="server"> <div id="rplist">
04.<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="True" oncheckedchanged="chkAll_CheckedChanged" Text="全选"/>
05.<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand">
06.<HeaderTemplate>
07.<table>
08.<tr>
09.<td colspan="6" style="text-align:center; background-color:#76a0ae; color:#ffffff; height:20px">新闻列表</td></tr>
10.<tr style="color:#1e486e">
11.<td>序号</td>
12.<td>新闻标题</td>
13.<td>发布时间</td>
14.<td colspan="3">操作</td>
15.</tr>
16.</HeaderTemplate>
17.<ItemTemplate>
18.<tr>
19.<td><asp:HiddenField ID="hfId" Value='<%#Eval("ID")%>' runat="server"/> <%# Eval("order")%></td>
20.<td class="tdleft"><%#Eval("NewsTitle")%></td>
21.<td><%# DataBinder.Eval(Container.DataItem,"CreateTime","{0:yyyy-M-d}")%></td>
22.<td><img alt="编辑" src="News/Images/writting.png" height="14" width="14"/>
23.<asp:LinkButton ID="lnkEdit" CommandName="EditData" runat="server">Edit</asp:LinkButton>
24.</td>
25.<td><img alt="删除" height="13" width="13" src="News/Images/cross.png"/>
26.<asp:LinkButton ID="lnkDelete" CommandName="DelData" runat="server">Delete</asp:LinkButton>
27.</td>
28.<td><asp:CheckBox ID="chkNews" runat="server"/></td>
29.</tr>
30.</ItemTemplate>
31.<AlternatingItemTemplate>
32.<tr style=" background-color:#f0f5f8">
33.<td><asp:HiddenField ID="hfId" Value='<%#Eval("ID")%>' runat="server"/> <%# Eval("order")%>
34.</td>
35.<td class="tdleft"><%#Eval("NewsTitle")%>
36.</td>
37.<td><%# DataBinder.Eval(Container.DataItem,"CreateTime","{0:yyyy-M-d}")%>
38.</td>
39.<td><img alt="编辑" src="News/Images/writting.png" height="14" width="14"/>
40.<asp:LinkButton ID="lnkEdit" CommandName="EditData" runat="server">Edit</asp:LinkButton>
41.</td>
42.<td><img alt="删除" height="13" width="13" src="News/Images/cross.png"/>
43.<asp:LinkButton ID="lnkDelete" CommandName="DelData" runat="server">Delete</asp:LinkButton>
44.</td>
45.<td><asp:CheckBox ID="chkNews" runat="server"/>
46.</td>
47.</tr>
48.</AlternatingItemTemplate>
49.<FooterTemplate>
50.<tr id="noData" runat="server" Visible="<%#Repeater1.Items.Count==0 %>" >
51.<td colspan="6">没有相关的数据</td>
52.</tr>
53.</table>
54.</FooterTemplate>
55.</asp:Repeater>
56.</div><div id="pager">
57.<table>
58. <tr>
59.<td>
60.总记录数:<asp:Label ID="lblCount" runat="server"></asp:Label>
61.</td>
62.<td >
63.第<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>页/ 共<asp:Label ID="labPage" runat="server"></asp:Label>
64.</td>
65.<td>
66.<asp:LinkButton ID="first" runat="server" οnclick="first_Click">首页
67.</asp:LinkButton>
68.<asp:LinkButton ID="up" runat="server" οnclick="up_Click">上一页
69.</asp:LinkButton>
70.<asp:LinkButton ID="next" runat="server" οnclick="next_Click">下一页
71.</asp:LinkButton>
72.<asp:LinkButton ID="last" runat="server" οnclick="last_Click">末页
73.</asp:LinkButton>
74.</td>
75.<td>
76.跳转:<asp:TextBox ID="txtPage" Width="50px" runat="server">
77.</asp:TextBox>
78.<asp:Button ID="btnGo" runat="server" Text="Go" οnclick="btnGo_Click"/>
79.</td>
80.</tr>
81.</table>
82.</div>
83.</form>
84.</body>
在首页上,我只实现几个导航的功能
新闻公告 >>更多
点击更多的时候 跳转到新闻公告首页
点击单条新闻标题时,跳转到显示这个新闻的全部内容的页面推荐商品 >>更多
点击更多的时候 跳转到商品信息首页
以图片滚动的形式显示商品信息,附带商品名字推荐求购
点击更多的时候 跳转到求购信息首页
同上 商品信息首页
以列表的形式显示
图片 名称 现价 上传时间
为了完成商品查询