logo

关于 利用DataGrid编辑、修改、删除记录 的评论:

评论日期:2006年12月14日 00:00:00 评论人:随便聊聊
是不是因为忘记在page_load事件里使用ispostback? 

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ''在此处放置初始化页的用户代码
        If Not IsPostBack Then           
                Datagrid1.bind()
        End If
    End Sub
评论日期:2007年01月11日 00:00:00 评论人:LLEY
上面哪个是SqlConnection的连接对象

至于下面哪个是DataSet中的虚拟表所使用的表名,可以随便设置表名,但使用是一定要用开始设置的名字,DataSet也可以不写这个参数,直接Fill(ds);
这个DataSet里虚拟表的表名就是默认的从0开始了使用的时候ds.Tables[0]...这样了.

我也是初学者,有什么不对的请指出,不要攻击我。。。
评论日期:2006年12月14日 00:00:00 评论人:随便聊聊
怎么发不了贴?
评论日期:2004年03月26日 00:00:00 评论人:aloner007
String strCnn = "Data Source=.;Initial Catalog=aa;User Id=sa;Password=;";  //这句语句是什么意思?
db_sqladaptor.Fill(ds,"MyDataResult");中的MyDataResult参数是什么意思!
评论日期:2004年04月12日 00:00:00 评论人:lqidiot
有没有用VB.NET语言写的,
我写了一个,但是不能实现"更新"这一功能
程序如下,能不能帮我改正一下
多谢了

 Dim conn As New SqlClient.SqlConnection("server=(local); database=lq; user id=sa; password=506")
        conn.Open()
        Dim Cmd As SqlClient.SqlCommand
        Dim SQL As String
        SQL = "Update zhuce Set [学号]=@学号, [姓名]=@姓名, [性别]=@性别, [专业]=@专业  Where [学号]=@Key"
        Cmd = New SqlClient.SqlCommand(SQL, conn)
        Cmd.Parameters.Add(New SqlClient.SqlParameter("@学号", SqlDbType.Int))
        Cmd.Parameters.Add(New SqlClient.SqlParameter("@姓名", SqlDbType.Char, 10))
        Cmd.Parameters.Add(New SqlClient.SqlParameter("@性别", SqlDbType.Char, 2))
        Cmd.Parameters.Add(New SqlClient.SqlParameter("@专业", SqlDbType.Char, 25))
        Cmd.Parameters.Add(New SqlClient.SqlParameter("@Key", SqlDbType.Int))
        Dim TB(4) As TextBox
        TB(1) = e.Item.Cells(2).Controls(0) ' 学号 TextBox
        TB(2) = e.Item.Cells(3).Controls(0) ' 姓名 TextBox                                                                    
        TB(3) = e.Item.Cells(4).Controls(0) ' 性别 TextBox
        TB(4) = e.Item.Cells(5).Controls(0) ' 专业 TextBox
        Label1.Text = Val(TB(1).Text) & TB(2).Text & TB(3).Text & TB(4).Text
        Cmd.Parameters("@Key").Value = mygrid.DataKeys(e.Item.ItemIndex)
        Cmd.Parameters("@学号").Value = Val(TB(1).Text)
        Cmd.Parameters("@姓名").Value = TB(2).Text
        Cmd.Parameters("@性别").Value = TB(3).Text
        Cmd.Parameters("@专业").Value = TB(4).Text
        Cmd.ExecuteNonQuery()
        Label2.Text = Cmd.Parameters("@学号").Value & Cmd.Parameters("@姓名").Value & Cmd.Parameters("@性别").Value & Cmd.Parameters("@专业").Value
        conn.Close()
        mygrid.EditItemIndex = -1
        open_bind()
评论日期:2004年06月12日 00:00:00 评论人:凌风雁
我这个没有办法实现删除功能!不知道为什么!!!可不可以帮助解决一下!!
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script language="vb" runat="server">
dim rcount,pcount,CurrentPage as integer
sub page_load(sender as object, e as eventargs)  '首次载入
if not page.IsPostBack then
   dim mana as string
   mana = request.QueryString("mname")
   if mana ="" then
      response.Redirect("/manage/admin.aspx")
      exit sub
   end if
   session("managename") = mana
   dim cn As OleDbConnection
   Dim cmd As OleDbDataadapter
   dim ds as dataset
   Dim sql As String = "select * from news order by id desc"
   dim dsn As String = application("dsn")
   cn = new oledbconnection(dsn)
   cmd = new oledbdataadapter
   cmd.tablemappings.add("Table","news")
   cmd.selectcommand = new oledbcommand(sql,cn)
   ds = new dataset("news")
   cmd.fill(ds,"news")
   RCount = ds.tables("news").defaultview.Count
   CurrentPage = 1
   if (RCount mod MyList.PageSize) = 0 then
      Pcount = Rcount/MyList.PageSize
      lblRecordCount.Text = RCount.ToString()  
      lblPageCount.Text = PCount.ToString()  
      lblCurrentPage.Text= "1"
   else 
      Pcount =cint( rcount/MyList.PageSize + 0.5)
  lblRecordCount.Text = RCount.ToString()  
      lblPageCount.Text = PCount.ToString()  
      lblCurrentPage.Text = "1"
   end if
   listsize()
   mylist.datasource = ds.tables("news").defaultview
   mylist.databind()
end if
end sub
sub change_page(sender As Object, e As DataGridPageChangedEventArgs) '换页
    mylist.CurrentPageIndex = e.NewPageIndex
   databind()
end sub
sub Page_OnClick(sender as object,e as commandeventargs) '响应按钮 
   CurrentPage = cint(lblCurrentPage.Text)
   PCount = cint(lblPageCount.Text)
   dim cmd1 as string
   cmd1 = e.CommandName
if cmd1 = "Next" then  
         if (CurrentPage < (PCount)) then 
 CurrentPage = currentpage + 1 
 end if
end if
if cmd1 = "Prev" then  
         if (CurrentPage > 0) then
 CurrentPage = currentpage - 1
 end if
end if
if cmd1 = "First" then  
      CurrentPage = 1
end if  
if cmd1 = "Last" then  
      CurrentPage = (PCount)
end if 
lblCurrentPage.Text = CurrentPage 
Listsize()
MyList.CurrentPageIndex = currentpage - 1
   databind()
end sub
sub Mylist_Delete(sender as object, e as DataGridCommandEventArgs)
dim mycn As OleDbConnection
    dim mycmd as OleDbCommand
Dim mysql As String = "delete from news where id = @id"
    dim mydsn As String = application("dsn")
mycn = New OleDbConnection(mydsn)
    mycmd = New OleDbCommand(mysql,mycn)
mycmd.Parameters.Add(New oledbParameter("@id",oledbtype.integer,4))
mycmd.Parameters("@id").Value =mylist.DataKeys(cint(e.Item.ItemIndex).tostring())
mycmd.Connection.Open()
    mycmd.ExecuteNonQuery()
mycmd.Connection.Close()
databind()
end sub    
function databind()
   dim cn As OleDbConnection
   Dim cmd As OleDbDataadapter
   dim ds as dataset
   Dim sql As String = "select * from news order by id desc"
   dim dsn As String = application("dsn")
   cn = new oledbconnection(dsn)
   cmd = new oledbdataadapter
   cmd.tablemappings.add("Table","news")
   cmd.selectcommand = new oledbcommand(sql,cn)
   ds = new dataset("news")
   cmd.fill(ds,"news")
   mylist.datasource = ds.tables("news").defaultview
   mylist.databind()
end function
function listsize()  '判断按钮可用与否
   lbnNextPage.Enabled = true  
   lbnPrevPage.Enabled = true 
   lbnLastPage.Enabled = true  
   lbnFirstPage.Enabled = true  
   if CurrentPage = PCount then    
      lbnNextPage.Enabled = false  
      lbnLastPage.Enabled = false
   end if
   if CurrentPage = 1 then 
   lbnPrevPage.Enabled = false 
   lbnFirstPage.Enabled = false  
   end if
   if currentpage = 1 and pcount = 1 then
   lbnNextPage.Enabled = false  
   lbnPrevPage.Enabled = false 
   lbnLastPage.Enabled = false 
   lbnFirstPage.Enabled = false
   end if 
end function
function formatstring(str as string) as string  '格式化输出字符
  str=str.replace(" ","  ")
  str=str.replace("<","<")
  str=str.replace(">",">")
  str=str.replace(vbcrlf,"<br>")
  formatstring = str
end function
function getchar(str_biaoti as string) as string  '截取字符
  if (str_biaoti.Length>20)
   return str_biaoti.Substring(0,20)+"……" 
  else 
   return str_biaoti
  end if
end function
</script>
<html>
<head>
<title>新闻中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../images/css.css" rel="stylesheet" type="text/css">
<script language="javaScript" type="text/javascript" SRC="/mousecolor.js"></script>
<script language="javascript"> 
    function newwin(url) 
     { 
    var popup; 
    url=url; 
    popup=window.open(url,null,"top=5,left=5,width=600,resizable=no,height=500,menubar=no,toolbar=no,scrollbars=yes,status=no"); 
    popup.focus(); 
     } 
</script>
<body>
<form runat="server">
  <table width="600" border="0" align="center">
  <tr><td valign="middle" bgcolor="#D6E7F7" colspan="2">    新闻管理系统</td></tr>
    <tr> 
      <td colspan="2" width="600" align="center"> <div align="center">
    <ASP:DataGrid id="MyList" 
    AllowPaging="True"       
    PagerStyle-Visible="false" 
PageSize="10"  
OnPageIndexChanged="change_page"  
    runat="server" 
    Width="550"
    GridLines="None"
    ShowFooter="false" 
    CellPadding="2"
    CellSpacing="1"
    Font-Name="宋体"
    Font-Size="8pt" 
    EnableViewState="false"
    AutoGenerateColumns="false" 
DataKeyField="id" 
    OnDeleteCommand="Mylist_Delete">
<Columns> 
<asp:BoundColumn ItemStyle-Width="150px" HeaderText="" DataField="时间" /> 
          <asp:HyperLinkColumn ItemStyle-Width="400px"    
                HeaderText=""    
                DataNavigateUrlField="id"    
                DataNavigateUrlFormatString="newsedit.aspx?id={0}"    
                DataTextField="标题"    
                 ></asp:HyperLinkColumn>
    <asp:ButtonColumn ItemStyle-Width="100px" Text="删除"  CommandName="Delete" /> 
     </Columns>
</asp:DataGrid></div>
</td>
    </tr>
<tr>
<td align="center" width="400">
<asp:LinkButton id="lbnFirstPage" Text="首页" CommandName="First" OnCommand="Page_OnClick" runat="server" />  
    <asp:LinkButton id="lbnPrevPage" Text="上一页" CommandName="Prev" OnCommand="Page_OnClick" runat="server" />  
    <asp:LinkButton id="lbnNextPage" Text="下一页" CommandName="Next" OnCommand="Page_OnClick" runat="server" />  
    <asp:LinkButton id="lbnLastPage" Text="末页" CommandName="Last" OnCommand="Page_OnClick" runat="server" /> 
共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录      
当前为<asp:Label id="lblCurrentPage" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" />页
</td>
<td align="left" width="200"><img src="images/insert.gif"><a href="addnews.aspx?mname=<%= session("managename") %>" target="manage frame">添加新闻</a></td>
</tr>
  </table>
</form>
</body>
</html>
评论日期:2005年02月23日 00:00:00 评论人:
原理很清楚,有的地方有些繁琐了。
评论日期:2006年02月18日 00:00:00 评论人:lqidiot
有没有用VB.NET语言写的,
我写了一个,但是不能实现"更新"这一功能
程序如下,能不能帮我改正一下
多谢了
评论日期:2006年02月26日 00:00:00 评论人:readbook8
借孟子老大的地发个广告!想知道鲁迅笔下小说《骆驼祥子》中的祥子老婆--虎妞是怎样死的吗?---->>读书吧!!!http://www.readbook8.com
评论日期:2006年02月26日 00:00:00 评论人:readbook8
借孟子老大的地发个广告!想知道鲁迅笔下小说《骆驼祥子》中的祥子老婆--虎妞是怎样死的吗?---->>读书吧!!!http://www.readbook8.com
评论日期:2006年02月26日 00:00:00 评论人:readbook8
借孟子老大的地发个广告!想知道鲁迅笔下小说《骆驼祥子》中的祥子老婆--虎妞是怎样死的吗?---->>读书吧!!!http://www.readbook8.com
评论日期:2006年04月22日 00:00:00 评论人:tu_long1234
我的也是没实现更新.
文什么没有更新。源代码如下
html:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="datagrid2.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 120px"
runat="server" PageSize="20" AutoGenerateColumns="False" AllowPaging="True" Width="424px">
<Columns>
<asp:BoundColumn DataField="文章编号" ReadOnly="True" HeaderText="文章编号"></asp:BoundColumn>
<asp:BoundColumn DataField="标题" HeaderText="标题"></asp:BoundColumn>
<asp:BoundColumn DataField="概要" HeaderText="概要"></asp:BoundColumn>
<asp:BoundColumn DataField="最后修改时间" HeaderText="最后修改时间"></asp:BoundColumn>
<asp:BoundColumn DataField="发表日期" ReadOnly="True" HeaderText="发表日期" DataFormatString="{0:yyyy-M-d}"></asp:BoundColumn>
<asp:HyperLinkColumn Text="点击查看" DataNavigateUrlField="文章编号" DataNavigateUrlFormatString="show.aspx?ID={0}"
DataTextField="文章编号" HeaderText="详细"></asp:HyperLinkColumn>
<asp:ButtonColumn Text="选择" HeaderText="选择" CommandName="Select"></asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="操作" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid></FONT></form>
</body>
</HTML>
Code-behind文件如下:
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 datagrid2
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public void BindGrid()
{
string strConn="server=(local);Initial Catalog=网站;user id=sa;password=19821225";
SqlConnection myconn=new SqlConnection(strConn);
SqlDataAdapter myAdapter=new SqlDataAdapter("select * from 文章",myconn);
DataSet ds=new DataSet();
myAdapter.Fill(ds,"文章");
DataGrid1.DataSource=ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
 BindGrid();

// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
private void DataGrid1_EditCommand(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
BindGrid();
}
private void DataGrid1_CancelCommand(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{DataGrid1.EditItemIndex=-1;
BindGrid();
}
private void DataGrid1_DeleteCommand(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(DataGrid1.Items.Count==1)
 {
 if(DataGrid1.CurrentPageIndex!=0)
 {
 DataGrid1.CurrentPageIndex=DataGrid1.CurrentPageIndex-1;
 }
 }
string strSql="delete from 文章 where 文章编号 =" +e.Item.Cells[0].Text+"";
ExecuteSql(strSql);
BindGrid();
}
private void ExecuteSql(string str)
{
try
{
string strconn="server=(local);Initial Catalog=网站;user id=sa;password=19821225";
SqlConnection myconn=new SqlConnection(strconn);
SqlCommand mycomm=new SqlCommand(str,myconn);
myconn.Open();
mycomm.ExecuteNonQuery();
myconn.Close();
}
catch(Exception e)
{
Response.Write("<script language='javascript'>alert('"+e.Message+"');</script>");
}
}
private void DataGrid1_UpdateCommand(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{   //载编辑状态和非编辑状态下是不同的
if(!IsPostBack)
{
string id=e.Item.Cells[0].Text;
string title=((TextBox)(e.Item.Cells[1].Controls[0])).Text;
string description=((TextBox)(e.Item.Cells[2].Controls[0])).Text;
string now=DateTime.Now.ToShortDateString();
e.Item.Cells[3].Text=now;
string strsql="update 文章 set 标题='"+title+"',概要='"+description+"',最后修改日期='"+now+"' where 文章编号 = "+id+"";
ExecuteSql(strsql);
DataGrid1.EditItemIndex=-1;
BindGrid();

}
}
    private void DataGrid1_PageIndexChanged(object sender,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}

}
}
感觉好像没有什么错!能删除就是不能更新。
而且我看了一下我的代码和你的代码本质上一样的为什么没有更新?


评论日期:2006年04月28日 00:00:00 评论人:sgjh
在DataGrid中最后一页只有一条数据时,删除这条记录后,系统出错,说当前页号大于最大页号,请问如何解决
评论日期:2006年05月28日 00:00:00 评论人:看看
晕,用VBNET写这个功能,有用这着这么多的代码吗?罗78索的。。。晕
评论日期:2006年06月14日 00:00:00 评论人:阿梅
孟子,牛B人物一个
借此推荐一个网站
http://www.obai.net
评论日期:2007年03月22日 00:00:00 评论人:zfsb13
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.OleDb;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
    
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//!IsPostBack
BindGrid();

}
private void BindGrid()
{
SqlCommand sqlCommandm =new SqlCommand();
sqlCommandm.CommandText="SELECT * FROM jobs ";
sqlConnection1.Open();

sqlCommandm.Connection = sqlConnection1;
SqlDataReader sqlDataReader = sqlCommandm.ExecuteReader();
DataGrid1.DataSource = sqlDataReader;
DataGrid1.DataBind();
sqlConnection1.Close();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{    
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
// 
// sqlConnection1
// 
this.sqlConnection1.ConnectionString = "workstation id=ECCENT;packet size=4096;integrated security=SSPI;data source=\".\";p" +
"ersist security info=False;initial catalog=pubs";
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
//this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
BindGrid();
}

private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
BindGrid();
}

private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string desc = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
string min  = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
string max  = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string id   =  DataGrid1.Items[(int)e.Item.ItemIndex].Cells[0].Text;

string SQL =" UPDATE jobs SET job_desc=''" + desc + ",min_lvl = "+ min +"'',max_lvl="+ max +" where job_id= "+ id ;

SqlCommand cm = new SqlCommand(SQL,sqlConnection1);
cm.CommandType = CommandType.Text;
DataGrid1.EditItemIndex = -1;
try
{
cm.ExecuteNonQuery();
Label1.Text="1111111111111111";
}
catch (SqlException se)
{
Label1.Text="sssssssssssssssss";
Label1.Style["color"]="red";
}
cm.Connection.Close();
BindGrid(); 
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlCommand cm = new SqlCommand("Delete From jobs Where job_id = " + DataGrid1.Items[(int)e.Item.ItemIndex].Cells[0].Text,sqlConnection1);
cm.CommandType = CommandType.Text;
cm.Connection.Open();
try
{
cm.ExecuteNonQuery();
Label1.Text="删除成功";
}
catch(SqlException)
{
Label1.Text="删除失败";
Label1.Style["color"]="red";
}
cm.Connection.Close();
BindGrid();
}

}
}
高手門
  幫我看看删除部分的
在就是每次我做更新的時候這個事件根本就不執行
      反正就是錯誤一大堆~
评论日期:2010年09月23日 14:52:12 评论人:
-1'
发表评论:(由于众所周知的原因,评论需要审核后才能显示,请勿重复发评论。谢谢!!)
标题:
用户名:
内容:
验证码: 请输入右边图像中的文字。验证码