温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:狂龙通讯录管理系统2.0源码
当前文件:
KuangLongCommunicationV2/editorGridview.aspx.cs[5K,2009-6-12 11:46:37],打开代码结构图
KuangLongCommunicationV2/editorGridview.aspx.cs[5K,2009-6-12 11:46:37],打开代码结构图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.Data.SqlClient; 12
13
14
public partial class editorGridview : System.Web.UI.Page 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (!IsPostBack) 19
{ 20
21
22
if (Session["userID"] == null || Session["userID"].ToString() == "") 23
{ 24
25
Page.Response.Redirect("default.aspx"); 26
} 27
else 28
{ 29
dataBind(); 30
} 31
if (GVuseage.Rows.Count == 0) 32
{ 33
34
Page.ClientScript.RegisterStartupScript(Page.GetType(),"script","alert('没有数据!');",true); 35
} 36
37
} 38
} 39
private void dataBind() 40
{ 41
42
string ID = Session["userId"].ToString(); 43
string sql2 = "select * from addresslist where userId='" + ID + "' order by id desc"; 44
DataBase DB2 = new DataBase(); 45
DataSet ds2 = DB2.DataAll(sql2); 46
GVuseage.DataSource = ds2; 47
GVuseage.DataKeyNames = new string[] { "id" }; 48
GVuseage.DataBind(); 49
return; 50
51
52
} 53
54
55
56
protected void GVuseage_RowDeleting(object sender, GridViewDeleteEventArgs e) 57
{ 58
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 59
int indexid = (int)GVuseage.DataKeys[e.RowIndex].Value; 60
string sql = "delete from AddressList where id=" + indexid; 61
SqlCommand cmd = new SqlCommand(sql,conn); 62
conn.Open(); 63
cmd.ExecuteNonQuery(); 64
dataBind(); 65
conn.Close(); 66
} 67
protected void GVuseage_RowEditing(object sender, GridViewEditEventArgs e) 68
{ 69
GVuseage.EditIndex = e.NewEditIndex; 70
dataBind(); 71
} 72
protected void GVuseage_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) 73
{ 74
GVuseage.EditIndex = -1; 75
dataBind(); 76
} 77
protected void GVuseage_RowUpdating(object sender, GridViewUpdateEventArgs e) 78
{ 79
SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 80
string uid = GVuseage.DataKeys[e.RowIndex].Values[0].ToString(); 81
82
string newfrdName = ((TextBox)(GVuseage.Rows[e.RowIndex].Cells[2].Controls[0])).Text.Trim(); 83
string newfrdPhone = ((TextBox)GVuseage.Rows[e.RowIndex].FindControl("txtphone")).Text.Trim(); 84
85
string newfrdMobilePhone = ((TextBox)GVuseage.Rows[e.RowIndex].FindControl("txtMobilePhone")).Text.Trim(); 86
string newfrdAddress = ((TextBox)(GVuseage.Rows[e.RowIndex].Cells[5].Controls[0])).Text.Trim(); 87
string newfrdQQ = ((TextBox)(GVuseage.Rows[e.RowIndex].Cells[6].Controls[0])).Text.Trim(); 88
string newfrdEmail = ((TextBox)GVuseage.Rows[e.RowIndex].FindControl("txtEmail")).Text.Trim(); 89
string newGeneral = ((TextBox)GVuseage.Rows[e.RowIndex].FindControl("txtGeneral")).Text.Trim(); 90
string sql2 = "update addresslist set frdName='" + newfrdName + "',frdPhone='" + newfrdPhone + "',frdMobilePhone='" + newfrdMobilePhone + "',frdAddress='" + newfrdAddress + "',frdQQ='" + newfrdQQ + "',frdEmail='" + newfrdEmail + "',General='" + newGeneral + "' where id=" + uid; 91
92
SqlCommand cmd = new SqlCommand(sql2, conn1); 93
conn1.Open(); 94
try 95
{ 96
cmd.ExecuteNonQuery(); 97
GVuseage.EditIndex = -1; 98
lblmsg.Text = "更新成功!"; 99
lblmsg.Style["color"] = "red"; 100
101
} 102
catch(SqlException) 103
{ 104
lblmsg.Text = "更新失败!"; 105
lblmsg.Style["color"] = "red"; 106
107
} 108
conn1.Close(); 109
dataBind(); 110
111
} 112
protected void Btnfirst_Click(object sender, EventArgs e) 113
{ 114
GVuseage.PageIndex = 0; 115
GVuseage.EditIndex = -1; 116
dataBind(); 117
118
lblmsg.Text = "共计" + GVuseage.PageCount + "页,现在已经是首页了"; 119
} 120
protected void Btndescend_Click(object sender, EventArgs e) 121
{ 122
if (GVuseage.PageIndex != 0) 123
{ 124
GVuseage.PageIndex--; 125
GVuseage.EditIndex = -1; 126
lblmsg.Text = "共计" + GVuseage.PageCount + "页"; 127
128
129
} 130
else 131
{ 132
GVuseage.PageIndex = 0; 133
GVuseage.EditIndex = -1; 134
lblmsg.Text = "共计" + GVuseage.PageCount + "页,现在已经是首页了"; 135
136
} 137
dataBind(); 138
} 139
protected void Btnretrusive_Click(object sender, EventArgs e) 140
{ 141
if (GVuseage.PageIndex != GVuseage.PageCount - 1) 142
{ 143
GVuseage.PageIndex++; 144
GVuseage.EditIndex = -1; 145
lblmsg.Text = "共计" + GVuseage.PageCount + "页"; 146
147
148
} 149
else 150
{ 151
GVuseage.PageIndex = GVuseage.PageCount - 1; 152
GVuseage.EditIndex = -1; 153
lblmsg.Text = "共计" + GVuseage.PageCount + "页,现在已经是尾页了"; 154
155
} 156
dataBind(); 157
} 158
protected void Btnfinally_Click(object sender, EventArgs e) 159
{ 160
if (GVuseage.Rows.Count == 0) 161
{ 162
Page.ClientScript.RegisterStartupScript(Page.GetType(), "script", "alert('没有数据!');", true); 163
} 164
165
else 166
{ 167
GVuseage.PageIndex = GVuseage.PageCount - 1; 168
GVuseage.EditIndex = -1; 169
dataBind(); 170
171
lblmsg.Text = "共计" + GVuseage.PageCount + "页,现在已经是尾页了"; 172
} 173
} 174
protected void GVuseage_PageIndexChanging(object sender, GridViewPageEventArgs e) 175
{ 176
GVuseage.PageIndex = e.NewPageIndex; 177
GVuseage.EditIndex = -1; 178
dataBind(); 179
180
} 181
} 182






}
}