温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Asp.net2.0的电影在线点播系统片段源码
当前文件:
MovieShowSample/search.aspx.cs,打开代码结构图
MovieShowSample/search.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.IO; 12
using System.Globalization; 13
using System.Reflection; 14
public partial class search : System.Web.UI.Page, ICallbackEventHandler 15
{ 16
//该源码下载自www.51aspx.com(51aspx.com) 17
18
protected void Page_Load(object sender, EventArgs e) 19
{ 20
//从cookie中获取身份验证票信息 21
string cookieName = FormsAuthentication.FormsCookieName; 22
HttpCookie authCookie = Context.Request.Cookies[cookieName]; 23
24
25
if (authCookie != null) 26
{ 27
div2.Visible = true; 28
//解密 29
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); 30
Link.Text = authTicket.Name.ToString(); 31
LinkRole.Text = authTicket.UserData.ToString(); 32
33
} 34
else 35
{ div2.Visible = false; } 36
37
ImageButton1.Attributes.Add("onclick","getResult();return false;"); 38
} 39
40
41
protected void Linkout_Click(object sender, EventArgs e) 42
{ 43
System.Web.Security.FormsAuthentication.SignOut(); 44
45
string url = "List.aspx?category=" + Request.QueryString["category"]; 46
Context.Response.Redirect(url); 47
} 48
protected void login_Click(object sender, ImageClickEventArgs e) 49
{ 50
if (txtid.Text != "" && txtpwd.Text != "") 51
{ 52
string UserName = txtid.Text.Trim(); 53
string UserPwd = txtpwd.Text.Trim(); 54
55
DataVisit mydv = new DataVisit();//创建访问层的类 56
if (mydv.Confirm(UserName, UserPwd))//验证用户是否合法 57
{ 58
string UserRoles = mydv.GetRoles(UserName);//获取用户角色的字符串 59
//建立身份验证票据对象 60
FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, DateTime.Now.AddHours(1), false, UserRoles, "/"); 61
//加密序列化验证票为字符串 62
string HashTicket = FormsAuthentication.Encrypt(Ticket); 63
//创建cookie 64
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket); 65
//输出cookie 66
Context.Response.Cookies.Add(UserCookie); 67
// div2.Visible = true; 68
string url = "List.aspx?category=" + Request.QueryString["category"]; 69
Context.Response.Redirect(url); 70
71
72
73
74
} 75
else 76
{ 77
txtid.Text = "不正确!用户名或密码"; 78
79
} 80
81
} 82
} 83
protected void register_Click(object sender, ImageClickEventArgs e) 84
{ 85
Response.Redirect("Register.aspx"); 86
} 87
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) 88
{ 89
90
91
if (e.Item.ItemType == ListItemType.Footer) 92
{ 93
ImageButton linkpre = (ImageButton)e.Item.FindControl("linkpre"); 94
ImageButton linknext = (ImageButton)e.Item.FindControl("linknext"); 95
DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList1"); 96
Label all = (Label)e.Item.FindControl("all"); 97
Label now = (Label)e.Item.FindControl("now"); 98
linknext.Enabled = false; 99
linkpre.Enabled = false; 100
101
int newpageIndex; 102
if (!Page.IsPostBack) 103
{ 104
newpageIndex = 0;//第一次加载时为第一页 105
106
} 107
else 108
{ 109
if (result == null)//如果回调参数为空 110
Session["page"] = 0;//session保存当前页面号 111
else 112
{ //由于回调结果在绑定事件之前 所以设置回调后的页面 保存在session中 113
string[] parts = result.Split('|'); 114
string n = parts[1]; 115
Session["page"] = n; 116
} 117
newpageIndex = Convert.ToInt32(Session["page"]); // 取出当前页面 118
} 119
120
if (newpageIndex > 0) 121
{ 122
linkpre.Enabled = true; 123
//设置回调事件 124
linkpre.Attributes.Add("onclick", "setpageto(" + (newpageIndex - 1).ToString() + ");return false;"); 125
} 126
if (newpageIndex < pds().PageCount - 1) 127
{ 128
129
linknext.Enabled = true; 130
//设置回调事件 131
linknext.Attributes.Add("onclick", "setpageto(" + (newpageIndex + 1).ToString() + "); return false;"); 132
} 133
134
135
136
for (int i = 1; i <= pds().PageCount; i++) 137
{ 138
ListItem item = new ListItem(); 139
item.Value = i.ToString(); 140
ddl.Items.Add(item); 141
} 142
ddl.Text = (newpageIndex + 1).ToString(); 143
ddl.Attributes.Add("onchange", "setpageto1(this); return false;"); 144
145
now.Text = pds(newpageIndex + 1).CurrentPageIndex.ToString(); 146
all.Text = pds().PageCount.ToString(); 147
148
149
150
151
152
} 153
154
155
} 156
157
158
159
//返回一个可分页的数据源 160
public PagedDataSource pds() 161
{ 162
PagedDataSource pds = new PagedDataSource(); 163
164
DataVisit mydv = new DataVisit(); 165
166
167
DataTable mydt = mydv.seachFilm(TextBox1.Text,TextBox2.Text,TextBox3.Text,TextBox4.Text); 168
169
pds.DataSource = mydt.DefaultView; 170
pds.AllowPaging = true; 171
int size = 9; 172
pds.PageSize = size; 173
pds.CurrentPageIndex = pds.CurrentPageIndex; 174
return pds; 175
} 176
//根据一个传来的整数作为当前页码并返回分页后的数据员 177
public PagedDataSource pds(int n) 178
{ 179
PagedDataSource pds = new PagedDataSource(); 180
181
DataVisit mydv = new DataVisit(); 182
183
184
DataTable mydt = mydv.seachFilm(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text); 185
186
pds.DataSource = mydt.DefaultView; 187
pds.AllowPaging = true; 188
int size = 9; 189
pds.PageSize = size; 190
pds.CurrentPageIndex = n; 191
return pds; 192
} 193
194
//绑定DataList 195
public void bind(int n) 196
{ 197
DataList1.DataSource = pds(n); 198
DataList1.DataBind(); 199
200
} 201
202
203
204
205
206
//回调方法 207
public string result; 208
public string GetCallbackResult() 209
{ 210
string[] parts = result.Split('|'); 211
//搜索名为MethodName的方法 212
MethodInfo method = this.GetType().GetMethod(parts[0]); 213
214
//定义一个object数组用来保存参数 215
object[] args = new object[parts.Length - 1]; 216
Array.Copy(parts, 1, args, 0,args.Length); 217
218
return (string)method.Invoke(this, args); 219
220
221
} 222
public void RaiseCallbackEvent(string eventArgument) 223
{ 224
result = eventArgument; 225
} 226
public string pageChange(string newIndex) 227
{ 228
229
int n = Convert.ToInt32(newIndex); 230
bind(n); 231
return getRenderCode(); 232
} 233
234
public string getRenderCode() 235
{ 236
StringWriter write1 = new StringWriter(CultureInfo.InvariantCulture); 237
HtmlTextWriter write2 = new HtmlTextWriter(write1); 238
239
DataList1.RenderControl(write2); 240
write2.Flush(); 241
write2.Close(); 242
243
return write1.ToString(); 244
245
} 246
//查询回调方法 247
public string filmResult(string index,string txt1,string txt2,string txt3,string txt4) 248
{ 249
int n = Convert.ToInt32(index); 250
TextBox1.Text = txt1.Trim(); 251
TextBox2.Text = txt2.Trim(); 252
TextBox3.Text = txt3.Trim(); 253
TextBox4.Text = txt4.Trim(); 254
if (TextBox1.Text == "") 255
TextBox1.Text = "null"; 256
if (TextBox2.Text == "") 257
TextBox2.Text = "null"; 258
if (TextBox3.Text == "") 259
TextBox3.Text = "null"; 260
if (TextBox4.Text == "") 261
TextBox4.Text = "null"; 262
bind(0); 263
return getRenderCode(); 264
} 265
}





}
}