急,刷新窗体时

CsharpDev 2003-08-21 07:36:54
请问,刷新窗体时,DataGrid会自动重复添加一条数据,请问这是怎么回事?急
...全文
20 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
CsharpDev 2003-08-21
  • 打赏
  • 举报
回复
其实也没有什么太大影响,如果没有办法的话
CsharpDev 2003-08-21
  • 打赏
  • 举报
回复
没有什么方法阻止它发生吗?
CsharpDev 2003-08-21
  • 打赏
  • 举报
回复
没有什么方法阻止它发生吗?
LongFire 2003-08-21
  • 打赏
  • 举报
回复
每按一次刷新,就会重复上一次操作
CsharpDev 2003-08-21
  • 打赏
  • 举报
回复
是的,添加完了,按了IE的刷新
wd_318 2003-08-21
  • 打赏
  • 举报
回复
这好象是asp/php中一样的问题嘛,ASP.NET也是这样吗?
yohomonkey 2003-08-21
  • 打赏
  • 举报
回复
你是不是添加完了,按了IE的刷新啊!
CsharpDev 2003-08-21
  • 打赏
  • 举报
回复
下面是新增纪录的代码


public void AddContinent(string EnglishName, string Name, string Picture)
{

// Create Instance of Connection and Command Object
SqlConnection continentConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand continentCommand = new SqlCommand("Soccer_AddContinent", continentConnection);

// Mark the Command as a SPROC
continentCommand.CommandType = CommandType.StoredProcedure;

SqlParameter parameterEnglishName = new SqlParameter("@EnglishName", SqlDbType.VarChar, 25);
parameterEnglishName.Value = EnglishName;
continentCommand.Parameters.Add(parameterEnglishName);

SqlParameter parameterName = new SqlParameter("@Name", SqlDbType.VarChar, 25);
parameterName.Value = Name;
continentCommand.Parameters.Add(parameterName);

SqlParameter parameterPicture = new SqlParameter("@Picture", SqlDbType.VarChar, 50);
parameterPicture.Value = Picture;
continentCommand.Parameters.Add(parameterPicture);

continentConnection.Open();
continentCommand.ExecuteNonQuery();
continentConnection.Close();
}
wd_318 2003-08-21
  • 打赏
  • 举报
回复
怎么看也不象是这些代码础的问题嘛,根本就没有新增记录的代码呀
CsharpDev 2003-08-21
  • 打赏
  • 举报
回复
按钮事件这里,添加一行数据后,刷新页面,发现DataGrid中多了一条一样的数据
CsharpDev 2003-08-21
  • 打赏
  • 举报
回复
namespace Customer.UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Customer.Components;
using System.Data.SqlClient;

/// <summary>
/// ContinentDataEnter 的摘要说明。
/// </summary>
public class ContinentDataEnter : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox TextBoxContinentEnglishName;
protected System.Web.UI.WebControls.TextBox TextBoxContinentName;
protected System.Web.UI.WebControls.TextBox TextBoxContinentPicture;
protected System.Web.UI.WebControls.DataGrid DataGridContinent;
protected System.Web.UI.WebControls.Label LabelContinent;
protected System.Web.UI.WebControls.Button ButtonContinentEnter;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

if(!Page.IsPostBack)
{
this.BindContinent();
}
}

private void BindContinent()
{
CatalogAdmin catalog = new CatalogAdmin();
this.DataGridContinent.DataSource = catalog.GetContinent();
this.DataGridContinent.DataKeyField = "ContinentID";
this.DataGridContinent.DataBind();
}

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

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ButtonContinentEnter.Click += new System.EventHandler(this.ButtonContinentEnter_Click);
this.DataGridContinent.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridContinent_CancelCommand);
this.DataGridContinent.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridContinent_EditCommand);
this.DataGridContinent.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridContinent_UpdateCommand);
this.DataGridContinent.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridContinent_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

//编辑命令
private void DataGridContinent_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGridContinent.EditItemIndex=e.Item.ItemIndex;
this.BindContinent();
}

//取消命令
private void DataGridContinent_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGridContinent.EditItemIndex = -1;
BindContinent();
}

//更新命令
private void DataGridContinent_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//声明变量
string ContinentID;
string EnglishName;
string Name;
string Picture;


ContinentID = this.DataGridContinent.DataKeys[e.Item.ItemIndex].ToString();
EnglishName = ((TextBox)(e.Item.Cells[1].Controls[0])).Text;
Name = ((TextBox)(e.Item.Cells[2].Controls[0])).Text;
Picture = ((TextBox)(e.Item.Cells[3].Controls[0])).Text;


CatalogAdmin catalog = new CatalogAdmin();


catalog.UpdateContinent(ContinentID,EnglishName,Name,Picture);


DataGridContinent.EditItemIndex = -1;

this.BindContinent();

}

//删除命令
private void DataGridContinent_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//声明变量
string ContinentID;


ContinentID = this.DataGridContinent.DataKeys[e.Item.ItemIndex].ToString();

CatalogAdmin catalog = new CatalogAdmin();

catalog.DeleteContinent(ContinentID);


this.BindContinent();


}
private void ClearValue()
{
this.TextBoxContinentEnglishName.Text="";
this.TextBoxContinentName.Text="";
this.TextBoxContinentPicture.Text="";
}

private void ButtonContinentEnter_Click(object sender, System.EventArgs e)
{
if (this.TextBoxContinentEnglishName.Text == "")
{
this.LabelContinent.Text = "没有填写英文名称";
return;
}
if (this.TextBoxContinentName.Text == "")
{
this.LabelContinent.Text = "没有填写名称";
return;
}
if (this.TextBoxContinentPicture.Text == "")
{
this.LabelContinent.Text = "没有填写地图信息";
return;
}

CatalogAdmin catalog = new CatalogAdmin();
catalog.AddContinent(this.TextBoxContinentEnglishName.Text,this.TextBoxContinentName.Text,this.TextBoxContinentPicture.Text);

this.BindContinent();
this.ClearValue();
}
}
}


帮看看到底什么问题
wd_318 2003-08-21
  • 打赏
  • 举报
回复
有代码会好查一点

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧