<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<Script Language="C#" runat="server">
OleDbConnection MyConn;
public void Page_Load(Object src,EventArgs e)
{
//连接语句
string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+"..\\data\\data.mdb;";
MyConn=new OleDbConnection(MyConnString);
MyConn.Open();
if (!Page.IsPostBack)
{
BindGrid();
}
}ICollection CreateTable()
{
string strSel="select * from admin";
DataSet ds=new DataSet();
OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,"usrGrid");
return ds.Tables["usrGrid"].DefaultView;}public void BindGrid()
{
usrGrid.DataSource=CreateTable();
usrGrid.DataBind();
}//处理Edit命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
usrGrid.EditItemIndex=(int)e.Item.ItemIndex;
BindGrid();
}
//取消
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
usrGrid.EditItemIndex=-1;
BindGrid();
} //处理update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
TableRow tr=e.Item;
e.Item.Cells[0].Width=600;
string ID=tr.Cells[0].Text;
string pwd=((TextBox)e.Item.Cells[2].Controls[0]).Text;
//Response.Write(pwd);
string strUpdate="Update admin Set [pwd]='"+pwd+"' where [id]="+ID;
OleDbCommand MyComm=new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();
usrGrid.EditItemIndex=-1;
BindGrid();
}//分页
public void DataGrid_PageChanged(Object sender,DataGridPageChangedEventArgs e)
{
usrGrid.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}//删除
public void DataGrid_ItemCommand(Object sender,DataGridCommandEventArgs e)
{
if(e.CommandName=="aa")
{
e.Item.Cells[4].Attributes.Add("onclick","javascript:return window.confirm('are you sure?');");
TableRow tr=e.Item;
string ID=tr.Cells[0].Text;
Response.Write(ID);
string strUpdate="Delete from admin where [id]="+ID;
OleDbCommand MyComm=new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();
usrGrid.EditItemIndex=-1;
BindGrid();
}
}
</Script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>东莞商务邮系统!</title>
<link href="css/pt9.css" rel="stylesheet" type="text/css">
</head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!--#include file="top.aspx"-->
<table width="100%" height="88%" border="0" cellpadding="0" cellspacing="0" class="pt9">
<tr>
<td width="16%" valign="top" bgcolor="#EEEEEE"><!--#include file="qxfpLeft.aspx"--> </td>
<td width="1" bgcolor="#427DB5"><img src="gif/1.gif" width="1" height="1"></td>
<td width="83%" valign="top"><font color="#000000"><br>
</font>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pt9"> 当前位置:用户查询</td>
</tr>
<tr>
<td></td>
</tr>
</table>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><form runat="server">
<asp:DataGrid id="usrGrid" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False"
OnEditCommand="DataGrid_EditCommand"
OnUpdateCommand="DataGrid_UpdateCommand"
OnCancelCommand="DataGrid_CancelCommand"
OnItemCommand="DataGrid_ItemCommand"
AllowPaging="True"
PageSize="5"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_PageChanged"
>
<Columns>
<asp:BoundColumn HeaderText="id" DataField="id" ReadOnly="True"/>
<asp:BoundColumn HeaderText="用户名" DataField="username" ReadOnly="True"/>
<asp:BoundColumn HeaderText="密码" DataField="pwd"/>
<asp:EditCommandColumn HeaderText="操作区"
EditText="修改密码"
UpdateText="更新"
CancelText="取消"
ButtonType="PushButton"
/>
<asp:ButtonColumn HeaderText="aa" Text="删除" CommandName="aa"/>
</Columns>
</asp:DataGrid>
</form></div></td>
</tr>
</table></td>
</tr>
</table></body>
</html>
大家帮我看看如何加确定删除对话框?谢谢!
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<Script Language="C#" runat="server">
OleDbConnection MyConn;
public void Page_Load(Object src,EventArgs e)
{
//连接语句
string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+"..\\data\\data.mdb;";
MyConn=new OleDbConnection(MyConnString);
MyConn.Open();
if (!Page.IsPostBack)
{
BindGrid();
}
}ICollection CreateTable()
{
string strSel="select * from admin";
DataSet ds=new DataSet();
OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,"usrGrid");
return ds.Tables["usrGrid"].DefaultView;}public void BindGrid()
{
usrGrid.DataSource=CreateTable();
usrGrid.DataBind();
}//处理Edit命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
usrGrid.EditItemIndex=(int)e.Item.ItemIndex;
BindGrid();
}
//取消
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
usrGrid.EditItemIndex=-1;
BindGrid();
} //处理update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
TableRow tr=e.Item;
e.Item.Cells[0].Width=600;
string ID=tr.Cells[0].Text;
string pwd=((TextBox)e.Item.Cells[2].Controls[0]).Text;
//Response.Write(pwd);
string strUpdate="Update admin Set [pwd]='"+pwd+"' where [id]="+ID;
OleDbCommand MyComm=new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();
usrGrid.EditItemIndex=-1;
BindGrid();
}//分页
public void DataGrid_PageChanged(Object sender,DataGridPageChangedEventArgs e)
{
usrGrid.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}//删除
public void DataGrid_ItemCommand(Object sender,DataGridCommandEventArgs e)
{
if(e.CommandName=="aa")
{
e.Item.Cells[4].Attributes.Add("onclick","javascript:return window.confirm('are you sure?');");
TableRow tr=e.Item;
string ID=tr.Cells[0].Text;
Response.Write(ID);
string strUpdate="Delete from admin where [id]="+ID;
OleDbCommand MyComm=new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();
usrGrid.EditItemIndex=-1;
BindGrid();
}
}
</Script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>东莞商务邮系统!</title>
<link href="css/pt9.css" rel="stylesheet" type="text/css">
</head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!--#include file="top.aspx"-->
<table width="100%" height="88%" border="0" cellpadding="0" cellspacing="0" class="pt9">
<tr>
<td width="16%" valign="top" bgcolor="#EEEEEE"><!--#include file="qxfpLeft.aspx"--> </td>
<td width="1" bgcolor="#427DB5"><img src="gif/1.gif" width="1" height="1"></td>
<td width="83%" valign="top"><font color="#000000"><br>
</font>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pt9"> 当前位置:用户查询</td>
</tr>
<tr>
<td></td>
</tr>
</table>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><form runat="server">
<asp:DataGrid id="usrGrid" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False"
OnEditCommand="DataGrid_EditCommand"
OnUpdateCommand="DataGrid_UpdateCommand"
OnCancelCommand="DataGrid_CancelCommand"
OnItemCommand="DataGrid_ItemCommand"
AllowPaging="True"
PageSize="5"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_PageChanged"
>
<Columns>
<asp:BoundColumn HeaderText="id" DataField="id" ReadOnly="True"/>
<asp:BoundColumn HeaderText="用户名" DataField="username" ReadOnly="True"/>
<asp:BoundColumn HeaderText="密码" DataField="pwd"/>
<asp:EditCommandColumn HeaderText="操作区"
EditText="修改密码"
UpdateText="更新"
CancelText="取消"
ButtonType="PushButton"
/>
<asp:ButtonColumn HeaderText="aa" Text="删除" CommandName="aa"/>
</Columns>
</asp:DataGrid>
</form></div></td>
</tr>
</table></td>
</tr>
</table></body>
</html>
大家帮我看看如何加确定删除对话框?谢谢!
解决方案 »
- sql数据库连接问题
- 求助:改写“缓存类”为线程安全的。
- IE 7.0 下按钮的 Attributes.Add 方法 !!
- 为何用下面的代码生成缩略图,执行到SAVE()时出现GDI+的错误,怎么解决
- 回调时系统脚本内出错
- 在ASP。net中如何动态控制网站的标题?
- 生成的静态页面,如新闻发布,在浏览时,怎样用<script src="xx.asp"></script>才能做到点击次数加1?
- 菜鸟请大虾帮忙 有关购物车的问题 (在线等 !!!!!急、急、急)
- 如何在往服务器上上传图片的同时,自动生成一个PictureName.htm文件?
- 这个问题很简单哟!
- 【【如何写心得体会?急~~~~】】
- asp.net中的数据存储问题
数数楼主的<asp:ButtonColumn HeaderText="aa" Text="删除" CommandName="aa"/>
在第几列?(从0开始的哦) Dim delBttn As LinkButton = e.Item.Cells(2).Controls(0)
delBttn.Attributes.Add("onclick", "javascript:return confirm('確認要刪除 " + e.Item.Cells(1).Text + " 此記錄嗎 ?');")
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim delBttn As LinkButton = e.Item.Cells(2).Controls(0)
delBttn.Attributes.Add("onclick", "javascript:return confirm('確認要刪除 " + e.Item.Cells(1).Text + " 此記錄嗎 ?');")
End IfEnd Sub
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<Script Language="C#" runat="server">
OleDbConnection MyConn;
public void Page_Load(Object src,EventArgs e)
{
连接语句
aa.Attributes.Add("onclick","javascript:return window.confirm('are you sure?');");
string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+"..\\data\\data.mdb;";
MyConn=new OleDbConnection(MyConnString);
MyConn.Open();
if (!Page.IsPostBack)
{
BindGrid();
}
}ICollection CreateTable()
{
string strSel="select * from admin";
DataSet ds=new DataSet();
OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,"usrGrid");
return ds.Tables["usrGrid"].DefaultView;}public void BindGrid()
{
usrGrid.DataSource=CreateTable();
usrGrid.DataBind();
}//处理Edit命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
usrGrid.EditItemIndex=(int)e.Item.ItemIndex;
BindGrid();
}
//取消
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
usrGrid.EditItemIndex=-1;
BindGrid();
} //处理update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
TableRow tr=e.Item;
e.Item.Cells[0].Width=600;
string ID=tr.Cells[0].Text;
string pwd=((TextBox)e.Item.Cells[2].Controls[0]).Text;
//Response.Write(pwd);
string strUpdate="Update admin Set [pwd]='"+pwd+"' where [id]="+ID;
OleDbCommand MyComm=new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();
usrGrid.EditItemIndex=-1;
BindGrid();
}//分页
public void DataGrid_PageChanged(Object sender,DataGridPageChangedEventArgs e)
{
usrGrid.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}//删除
public void DataGrid_ItemCommand(Object sender,DataGridCommandEventArgs e)
{
if(e.CommandName=="aa")
{
// e.Item.Cells[4].Attributes.Add("onclick","javascript:return window.confirm('are you sure?');");
TableRow tr=e.Item;
string ID=tr.Cells[0].Text;
Response.Write(ID);
string strUpdate="Delete from admin where [id]="+ID;
OleDbCommand MyComm=new OleDbCommand(strUpdate,MyConn);
MyComm.ExecuteNonQuery();
usrGrid.EditItemIndex=-1;
BindGrid();
}
}</Script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>东莞商务邮系统!</title>
<link href="css/pt9.css" rel="stylesheet" type="text/css">
</head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!--#include file="top.aspx"-->
<table width="100%" height="88%" border="0" cellpadding="0" cellspacing="0" class="pt9">
<tr>
<td width="16%" valign="top" bgcolor="#EEEEEE"><!--#include file="qxfpLeft.aspx"--> </td>
<td width="1" bgcolor="#427DB5"><img src="gif/1.gif" width="1" height="1"></td>
<td width="83%" valign="top"><font color="#000000"><br>
</font>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pt9"> 当前位置:用户查询</td>
</tr>
<tr>
<td></td>
</tr>
</table>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><form runat="server">
<asp:DataGrid id="usrGrid" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False"
OnEditCommand="DataGrid_EditCommand"
OnUpdateCommand="DataGrid_UpdateCommand"
OnCancelCommand="DataGrid_CancelCommand"
OnItemCommand="DataGrid_ItemCommand"
AllowPaging="True"
PageSize="5"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_PageChanged"
>
<Columns>
<asp:BoundColumn HeaderText="id" DataField="id" ReadOnly="True"/>
<asp:BoundColumn HeaderText="用户名" DataField="username" ReadOnly="True"/>
<asp:BoundColumn HeaderText="密码" DataField="pwd"/>
<asp:EditCommandColumn HeaderText="操作区"
EditText="修改密码"
UpdateText="更新"
CancelText="取消"
ButtonType="PushButton"
/>
<asp:ButtonColumn HeaderText="aa" Text="删除" CommandName="aa" />
</Columns>
</asp:DataGrid>
</form></div></td>
</tr>
</table></td>
</tr>
</table></body>
</html>
不是aa,是你的控件名