zoukankan
html css js c++ java
编辑 删除 分页
<%
@ Page language
=
"
c#
"
Codebehind
=
"
WebForm1.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
kaoshi.WebForm1
"
%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
HTML
>
<
HEAD
>
<
title
>
WebForm1
</
title
>
<
meta
name
="GENERATOR"
Content
="Microsoft Visual Studio .NET 7.1"
>
<
meta
name
="CODE_LANGUAGE"
Content
="C#"
>
<
meta
name
="vs_defaultClientScript"
content
="JavaScript"
>
<
meta
name
="vs_targetSchema"
content
="http://schemas.microsoft.com/intellisense/ie5"
>
</
HEAD
>
<
body
MS_POSITIONING
="GridLayout"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<
TABLE
id
="Table1"
cellSpacing
="1"
cellPadding
="1"
width
="380"
align
="center"
border
="0"
>
<
TR
>
<
TD
></
TD
>
</
TR
>
<
TR
>
<
TD
class
="red12"
height
="30"
>
<
asp:label
id
="lblProcess"
runat
="server"
></
asp:label
>
<
asp:textbox
id
="txtClssid"
runat
="server"
Visible
="False"
Width
="16px"
Height
="12px"
></
asp:textbox
></
TD
>
</
TR
>
<
TR
>
<
TD
align
="center"
>
<
asp:datagrid
id
="gridRoot"
style
="FONT-SIZE: 9pt"
runat
="server"
HorizontalAlign
="Center"
OnDeleteCommand
="gridRoot_Delete"
OnUpdateCommand
="gridRoot_Update"
OnCancelCommand
="gridRoot_Cancel"
OnEditCommand
="gridRoot_Edit"
DataKeyField
="id"
BorderColor
="black"
BorderWidth
="1"
autogeneratecolumns
="False"
HeaderStyle-BackColor
="#67bcce"
OnPageIndexChanged
="grid_PageChanged"
PageSize
="20"
PagerStyle-HorizontalAlign
="Right"
PagerStyle-Mode
="NumericPages"
AllowPaging
="True"
CellSpacing
="0"
CellPadding
="4"
width
="500px"
>
<
HeaderStyle
BackColor
="#67BCCE"
></
HeaderStyle
>
<
Columns
>
<
asp:BoundColumn
DataField
="id"
ReadOnly
="True"
HeaderText
="序号"
>
<
HeaderStyle
HorizontalAlign
="Center"
Height
="30px"
Width
="50px"
></
HeaderStyle
>
<
ItemStyle
Font-Names
="verdana"
HorizontalAlign
="Center"
BackColor
="#EEEEEE"
></
ItemStyle
>
</
asp:BoundColumn
>
<
asp:TemplateColumn
SortExpression
="Typ"
HeaderText
="产品型号"
>
<
HeaderStyle
HorizontalAlign
="Center"
Width
="180px"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
="Center"
BackColor
="#EEEEEE"
></
ItemStyle
>
<
ItemTemplate
>
<
asp:Label
id
=Label1
runat
="server"
Text
='<%#
DataBinder.Eval(Container.DataItem, "Typ") %
>
'>
</
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
NOBR
>
<
asp:TextBox
id
=Typ
runat
="server"
Width
="94px"
Text
='<%#
DataBinder.Eval(Container.DataItem, "Typ") %
>
'>
</
asp:TextBox
>
<
asp:RequiredFieldValidator
id
="clssReqVal"
runat
="server"
Font-Size
="12"
Font-Name
="Verdana"
Display
="Dynamic"
ControlToValidate
="Typ"
>
*
</
asp:RequiredFieldValidator
></
NOBR
>
</
EditItemTemplate
>
</
asp:TemplateColumn
>
<
asp:TemplateColumn
SortExpression
="Factory"
HeaderText
="工厂名称"
>
<
HeaderStyle
HorizontalAlign
="Center"
Width
="180px"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
="Center"
BackColor
="#EEEEEE"
></
ItemStyle
>
<
ItemTemplate
>
<
asp:Label
id
="Label2"
runat
="server"
Text
='<%#
DataBinder.Eval(Container.DataItem, "Factory") %
>
'>
</
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
NOBR
>
<
asp:TextBox
id
="Factory"
runat
="server"
Width
="94px"
Text
='<%#
DataBinder.Eval(Container.DataItem, "Factory") %
>
'>
</
asp:TextBox
>
<
asp:RequiredFieldValidator
id
="Requiredfieldvalidator1"
runat
="server"
Font-Size
="12"
Font-Name
="Verdana"
Display
="Dynamic"
ControlToValidate
="Factory"
>
*
</
asp:RequiredFieldValidator
></
NOBR
>
</
EditItemTemplate
>
</
asp:TemplateColumn
>
<
asp:EditCommandColumn
ButtonType
="LinkButton"
UpdateText
="更新"
HeaderText
="编辑"
CancelText
="取消"
EditText
="编辑"
>
<
HeaderStyle
HorizontalAlign
="Center"
Width
="100px"
></
HeaderStyle
>
<
ItemStyle
Wrap
="False"
HorizontalAlign
="Center"
BackColor
="#EEEEEE"
></
ItemStyle
>
</
asp:EditCommandColumn
>
<
asp:ButtonColumn
Text
="删除"
HeaderText
="删除"
CommandName
="Delete"
>
<
HeaderStyle
HorizontalAlign
="Center"
Width
="50px"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
="Center"
BackColor
="#EEEEEE"
></
ItemStyle
>
</
asp:ButtonColumn
>
</
Columns
>
<
PagerStyle
HorizontalAlign
="Right"
Mode
="NumericPages"
></
PagerStyle
>
</
asp:datagrid
></
TD
>
</
TR
>
</
TABLE
>
</
form
>
</
body
>
</
HTML
>
cs
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
namespace
kaoshi
{
/**/
///
<summary>
///
WebForm1 的摘要说明。
///
</summary>
public
class
WebForm1 : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.Label lblProcess;
protected
System.Web.UI.WebControls.TextBox txtClssid;
protected
System.Web.UI.WebControls.DataGrid gridRoot;
SqlConnection thisConnection
=
new
SqlConnection(
"
server=localhost;Database=stst;uid=sa;pwd=fan
"
);
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
if
(
!
this
.IsPostBack)
BindGrid();
}
public
void
BindGrid()
{
SqlDataAdapter myCommand
=
new
SqlDataAdapter(
"
select * from FactoryType order by Factory
"
,thisConnection);
DataSet ds
=
new
DataSet();
myCommand.Fill(ds,
"
xatop
"
);
gridRoot.DataSource
=
ds.Tables[
"
xatop
"
].DefaultView;
gridRoot.DataBind();
}
public
void
gridRoot_Edit(Object sender, DataGridCommandEventArgs e)
{
gridRoot.EditItemIndex
=
(
int
)e.Item.ItemIndex;
BindGrid();
}
public
void
grid_PageChanged(
object
sender, DataGridPageChangedEventArgs e)
{
gridRoot.CurrentPageIndex
=
e.NewPageIndex;
BindGrid();
}
public
void
gridRoot_Delete(Object sender, DataGridCommandEventArgs e)
{
String deleteCmd
=
"
DELETE from FactoryType where id = @Id
"
;
SqlCommand myCommand
=
new
SqlCommand(deleteCmd, thisConnection);
myCommand.Parameters.Add(
new
SqlParameter(
"
@Id
"
, SqlDbType.NVarChar,
11
));
myCommand.Parameters[
"
@Id
"
].Value
=
gridRoot.DataKeys[(
int
)e.Item.ItemIndex];
myCommand.Connection.Open();
try
{
myCommand.ExecuteNonQuery();
lblProcess.Text
=
"
<b>已删除记录</b>
"
;
}
catch
(SqlException)
{
lblProcess.Text
=
"
错误:未能删除记录
"
;
lblProcess.Style[
"
color
"
]
=
"
red
"
;
}
myCommand.Connection.Close();
BindGrid();
}
public
void
gridRoot_Cancel(Object sender, DataGridCommandEventArgs e)
{
gridRoot.EditItemIndex
=
-
1
;
BindGrid();
}
public
void
gridRoot_Update(Object sender, DataGridCommandEventArgs e)
{
string
colvalue
=
((TextBox)e.Item.FindControl(
"
Typ
"
)).Text;
String updateCmd
=
"
UPDATE FactoryType SET Typ = @Typ,Factory=@Factory where id = @Id
"
;
SqlCommand myCommand
=
new
SqlCommand(updateCmd, thisConnection);
myCommand.Parameters.Add(
new
SqlParameter(
"
@Id
"
, SqlDbType.NVarChar,
11
));
myCommand.Parameters.Add(
new
SqlParameter(
"
@Typ
"
, SqlDbType.NVarChar,
40
));
myCommand.Parameters.Add(
new
SqlParameter(
"
@Factory
"
, SqlDbType.NVarChar,
40
));
myCommand.Parameters[
"
@Id
"
].Value
=
gridRoot.DataKeys[(
int
)e.Item.ItemIndex];
myCommand.Parameters[
"
@Typ
"
].Value
=
((TextBox)e.Item.FindControl(
"
Typ
"
)).Text;
myCommand.Parameters[
"
@Factory
"
].Value
=
((TextBox)e.Item.FindControl(
"
Factory
"
)).Text;
myCommand.Connection.Open();
try
//
捕捉错误
{
myCommand.ExecuteNonQuery();
lblProcess.Text
=
"
<b>已更新记录</b>
"
;
gridRoot.EditItemIndex
=
-
1
;
}
catch
(SqlException b)
{
if
(b.Number
==
2627
)
lblProcess.Text
=
"
错误:已存在具有相同主键的记录
"
;
else
lblProcess.Text
=
"
错误:未能更新记录,请确保正确填写了字段
"
;
lblProcess.Style[
"
color
"
]
=
"
red
"
;
}
myCommand.Connection.Close();
//
更新数据完毕
BindGrid();
//
DdlLst(e);
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.gridRoot.PageIndexChanged
+=
new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(
this
.grid_PageChanged);
this
.gridRoot.CancelCommand
+=
new
System.Web.UI.WebControls.DataGridCommandEventHandler(
this
.gridRoot_Cancel);
this
.gridRoot.EditCommand
+=
new
System.Web.UI.WebControls.DataGridCommandEventHandler(
this
.gridRoot_Edit);
this
.gridRoot.UpdateCommand
+=
new
System.Web.UI.WebControls.DataGridCommandEventHandler(
this
.gridRoot_Update);
this
.gridRoot.DeleteCommand
+=
new
System.Web.UI.WebControls.DataGridCommandEventHandler(
this
.gridRoot_Delete);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
}
}
查看全文
相关阅读:
linux分区
MySQL
RGB中的颜色的设置
解决UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 12: ordinal not in range(128)的编码问题
解决运行scrapy是报错No module named cryptography,解决cryptography的安装问题,解决libffi的安装问题
解决pycharm下安装reportLab报错的问题
简单的爬取并下载图片的程序
linux常用命令
ubuntu下安装pycharm的方法
win7下装ubuntu双系统后无法进入win7的解决方法
原文地址:https://www.cnblogs.com/voodgen/p/100253.html
最新文章
Leangoo英文版来了~
Scrum Master角色可能消失吗?
推荐Leangoo团队协作的20个理由
scrum敏捷开发的几款工具
反对迭代0:停止拖延,开始迭代
故事点数是对工时的度量
是时候取消Sprint评审会议了吗?
Leangoo项目协作工具——用户设置
不要轻易挑战用户的习惯,否则会被用户打脸!
INVEST原则的应用
热门文章
一起刷LeetCode4-Median of Two Sorted Arrays
一起刷LeetCode3-Longest Substring With Repeating Characters
一起刷LeetCode2-Add Two Numbers
一起刷LeetCode1-Two Sum
只有IE能上网,其他浏览器均不可以!
Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
机器学习笔试面试系列算法集锦
动手实践:在Windows上安装NumPy、Matplotlib、SciPy和IPython
将 Sublime 3 打造成 Python/Django IDE
Tkinter教程之Canvas篇(2)
Copyright © 2011-2022 走看看