快下班了
[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
晕了,下面是原代码:
<script language="C#" runat="server">
OleDbConnection MyConn;
public void Page_Load(Object src,EventArgs e)
{
//连接词句
string MyConnString = " Provider=Micorsoft.Jet.LOEDB.4.0; Data Source="+Server.MapPath("//")+"DataBase\\db1.mdb";
MyConn=New OleDbConnection(MyConnString);
MyConn.open();
if (!Page.IsPostBack)
{
BingdGrid();
}
}
ICollection CreateTable()
{
string strsel="select * form score";
Dateset ds=new Dateset();
OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strsel,Myconn);
MyAdapter.Fill(ds."score");
return ds.Tables("score").DefaultView;
}
public void BindGrid()
{
score.Datasource=CreateTable();
score.DataBind();
}
//处理EDIT命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemIndex=(int)e.Item.Itemindex;
BindGrid();
}
//处理Cancel命令
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemindex=-1;
BindGrid();
}
//处理update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
string strname=e.Item.Cells[1].Text;
int intChinese=
Int32.parse(((Textbox)e.Item.Cells[2].Controls[0]).Text);
int intMath=
Int32.Parse(((Textbox)e.Item.Cells[3].Controls[0]).Text);
int intEnglish=
Int32.Parse(((Textbox)e.Item.Cells[4].Controls[0]).Text);
//更新数据库的数据
string strupdate="update score set chinese="+intchinese+",math="+intmath+",endlish="+intenglish+" where name=''"+strname+"";
OleDbCommand mycomm=new OledbCommmand(strupdate,myconn);
mycomm.executenonquery();
score.editItemindex=-1;
bindgrid();
}
</script>
不行的,现在也下班了,明天没事时帮我测试一下,我从书上原样写的代码,不知哪里不行,谢谢,下面是全部代码:
<%@ Page Language="C#" %>
<% @ import namespace="System.Data" %>
<% @ import namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
public OleDbConnection MyConn;
public void Page_Load(Object src,EventArgs e)
{
//连接词句
string MyConnString = " Provider=Micorsoft.Jet.LOEDB.4.0; Data Source="+Server.MapPath("//")+"DataBase\\db1.mdb";
MyConn=New OleDbConnection(MyConnString);
MyConn.open();
if (!Page.IsPostBack)
{
BingdGrid();
}
}
ICollection CreateTable()
{
string strsel="select * form score";
Dateset ds=new Dateset();
OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strsel,Myconn);
MyAdapter.Fill(ds."score");
return ds.Tables("score").DefaultView;
}
public void BindGrid()
{
score.Datasource=CreateTable();
score.DataBind();
}
//处理EDIT命令
public void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemIndex=(int)e.Item.Itemindex;
BindGrid();
}
//处理Cancel命令
public void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
{
score.EditItemindex=-1;
BindGrid();
}
//处理update命令
public void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
{
//更新数据库中的信息
string strname=e.Item.Cells[1].Text;
int intChinese=
Int32.parse(((Textbox)e.Item.Cells[2].Controls[0]).Text);
int intMath=
Int32.Parse(((Textbox)e.Item.Cells[3].Controls[0]).Text);
int intEnglish=
Int32.Parse(((Textbox)e.Item.Cells[4].Controls[0]).Text);
//更新数据库的数据
string strupdate="update score set chinese="+intchinese+",math="+intmath+",endlish="+intenglish+" where name=''"+strname+"";
OleDbCommand mycomm=new OledbCommmand(strupdate,myconn);
mycomm.executenonquery();
score.editItemindex=-1;
bindgrid();
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<center>
<b>演示editcommmandcloumn</b>
<asp:DataGrid id="score" runat="server"
headerstyle-backcolor="#aaaadd"
alternatingitemstyle-backcolor="#eeeeee"
autogeneratecolumns="false"
oneditcommand="DataGrid_Editcommand"
onUpdateCommand="DataGrid_UpdateCommand"
onCancelCommand="FataGrid_CancelCommand">
<Columns>
<asp:EditCommandColumn HeaderText="操作区"
EditText="编辑"
UpdateText="更新"
CancelText="取消"
ButtonType="PushButton" />
<asp:BoundColumn HeaderText="姓名" DataField="name" Readonly="true" />
<asp:BoundColumn HeaderText="语文" DataField="Chinese" />
<asp:BoundColumn HeaderText="数学" DataField="Math" />
<asp:BoundColumn HeaderText="英语" DataField="English" />
</Columns>
</asp:DataGrid>
</center>
</form>
</body>
</html>