MESSAGE 是那个Label吗的ID吗
解决方案 »
- c# 点击文字有按钮的的效果怎么实现啊 新手求教~~~~!
- devexpress的gridcontrol控件能否 用不同颜色显示修改过的数据?
- 执行一条长时间sql的问题
- 扩展方法怎么理解的?
- .NET互操作问题:C结构体如何简单地在C#中使用?
- C# WinForm: 如 何 在 richtextbox 里 插 入 一 张 图 片 ( 不 能 操 作 剪 贴 板 )
- 讨论C#最基础的东东
- 如何在C#中使用Windows API函数???
- 找工作找到自己没信心
- 什么是可合并(composed)的代理类型?
- 请教~~C# winform下combox显示问题
- C#中如何自动登录到需要cookie的网站
例如:Page.Response.Write("<script>alert('错误:已存在具有相同主键的记录';)</script>")
如果你想它在編輯行顯示﹐可以添加模板列﹐在模板列中添加一個label顯示錯誤信息。例﹕
((Label)Grid.Items[i].Cells[j].Controls[0]).Text ="错误:已存在具有相同主键的记录";
例如:Page.Response.Write("<script>alert('错误:已存在具有相同主键的记录';)</script>")
是在HTML中添加吗??
高分求!!
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;public class View : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGridView;
private string connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; private void BindDataGrid()
{
SqlConnection cn = new SqlConnection(connectionString);
SqlCommand da = new SqlCommand( "Select * From Note", cn );
cn.Open();
DataGridView.DataSource = cmd.ExecuteReader();
DataGridView.DataKeyField = "id";
DataGridView.DataBind();
cn.Close();
} private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack )
{
BindDataGrid();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.DataGridView.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridView_CancelCommand);
this.DataGridView.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridView_EditCommand);
this.DataGridView.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridView_UpdateCommand);
this.DataGridView.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridView_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void DataGridView_EditCommand(object source, DataGridCommandEventArgs e)
{
DataGridView.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
} private void DataGridView_CancelCommand(object source, DataGridCommandEventArgs e)
{
DataGridView.EditItemIndex = -1;
BindDataGrid();
} private void DataGridView_UpdateCommand(object source, DataGridCommandEventArgs e)
{
TextBox txtName = (TextBox)e.Item.Cells[0].FindControl("txtName");
TextBox txtEmail = (TextBox)e.Item.Cells[1].FindControl("txtEmail");
TextBox txtNotes = (TextBox)e.Item.Cells[3].FindControl("txtNotes"); SqlConnection cn = new SqlConnection( connectionString);
string strUpdate = "Update Note set Username = @username, Email = @email, PostTime = @posttime, text= @text Where id = @id";
SqlCommand cmd = new SqlCommand(strUpdate, cn );
cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = txtName.Text;
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = txtEmail.Text;
cmd.Parameters.Add("@posttime", SqlDbType.DateTime).Value = DateTime.Now;
cmd.Parameters.Add("@text", SqlDbType.Text).Value = txtNotes.Text;
cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = DataGridView.DataKeys[e.Item.ItemIndex].ToString();
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
DataGridView.EditItemIndex = -1;
BindDataGrid();
} private void DataGridView_DeleteCommand(object source, DataGridCommandEventArgs e)
{
SqlConnection cn = new SqlConnection( connectionString);
string strDelete = "delete from Note Where id = @id";
SqlCommand cmd = new SqlCommand(strDelete, cn );
cmd.Parameters.Add("@id", SqlDbType.VarChar).Value = DataGridView.DataKeys[e.Item.ItemIndex].ToString();
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
DataGridView.EditItemIndex = -1;
BindDataGrid();
}
}
http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032328189&Culture=zh-CN