急急急!!!为什么在设计器中定义的ButtonColumn和EditCommandColumn运行时用不了???

Bright1982 2002-08-02 01:52:15
为什么在设计器中定义的ButtonColumn和EditCommandColumn运行时用不了???

我在设计器中DataGrid里添加了ButtonColumn(Delete)和EditCommandColumn(Edit),不过在代码部分看不到有什么变化,运行时按下Delete或Edit按钮,没有触发DeleteCommand事件和EditCommand事件!
这是为什么???

还有,我自己在Page_Load函数里写了这两个控键,Delete可以用了,Edit按下去也能触发它的事件了,但是,当触发EditCommand事件后(Edit按钮被Cancel和Save两个按钮代替了),这时按了Cancel或Save按钮又没有用了,不能触发CancelCommad和UpdateCommand事件!!!
这又是为什么呀???

望高手指点!!!
谢谢!!!
...全文
42 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bright1982 2002-08-15
  • 打赏
  • 举报
回复
Faint!!!
我把按钮类型改成LinkButton竟然就可以用了!!!

难道这是个Bug???
yohomonkey 2002-08-14
  • 打赏
  • 举报
回复
<script language="javascript">
function postback(para1, para2){
__doPostBack(para1, para2);
}
</script>
这个不要少!!!!!!!!!!!!
yohomonkey 2002-08-14
  • 打赏
  • 举报
回复
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Materials.aspx.vb" Inherits="Lov.Materials"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Materials</title>
<script language="javascript">
function postback(para1, para2){
__doPostBack(para1, para2);
}
</script>
<LINK href="Choice.css" type="text/css" rel="stylesheet">
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body leftMargin="0" topMargin="0" MS_POSITIONING="GridLayout">
<form id="Form1" style="COLOR: darkviolet; BACKGROUND-COLOR: #ccccff" method="post" runat="server">
<asp:datagrid id="dgm1" style="Z-INDEX: 103" runat="server" ForeColor="Navy" CellPadding="0" BorderWidth="1px" BorderColor="Black" AutoGenerateColumns="False" Width="99%">
<SelectedItemStyle HorizontalAlign="Center" ForeColor="Black" CssClass="clsDataGridItem2" BackColor="Lime"></SelectedItemStyle>
<AlternatingItemStyle HorizontalAlign="Center" Height="20px" CssClass="clsdatagriditem0" BackColor="#EBFFFF"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center" Height="20px" CssClass="clsDataGridItem1" BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="Large" Font-Bold="True" HorizontalAlign="Center" Height="25px" CssClass="clsDataGridHeader" BackColor="LightSkyBlue"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Ins" HeaderText="Insert" CommandName="insert">
<ItemStyle Width="50px"></ItemStyle>
</asp:ButtonColumn>
<asp:ButtonColumn Text="Del" HeaderText="Delete" CommandName="Delete">
<ItemStyle Width="50px"></ItemStyle>
</asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Command" CancelText="Cancel" EditText="Edit">
<ItemStyle Width="50px"></ItemStyle>
</asp:EditCommandColumn>
</asp:datagrid>
</form>
</body>
</HTML>
yohomonkey 2002-08-14
  • 打赏
  • 举报
回复
主要是asp的html脚本的问题,
你的脚本是不是
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
?????????????????????????????????

delete要用_itemcommand来调用:
例如:
Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgContainerS.ItemCommand

Select Case e.CommandName.ToUpper
Case "delete"
do .........delete
end select


另一方法就是在html的脚本中加入自己定义的事件,只要可以auotpostbac即可!下面是html代码!
Bright1982 2002-08-13
  • 打赏
  • 举报
回复
还有:


private void Button1_Click(object sender, System.EventArgs e)
{
this.sqlCommand2.Parameters["@Name"].Value=TextBoxName.Text;
this.sqlCommand2.Parameters["@Class"].Value=TextBoxClass.Text;
this.sqlCommand2.Parameters["@ID"].Value=TextBoxID.Text;
this.sqlCommand2.Parameters["@PassWord"].Value=TextBoxID.Text;
this.sqlCommand2.ExecuteNonQuery();
TextBoxName.Text=null;
TextBoxClass.Text=null;
TextBoxID.Text=null;
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(dataSet11,"BasicInformation");
this.DataGrid1.DataBind();
}

public void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(dataSet11,"BasicInformation");
this.DataGrid1.DataBind();
}

private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
}

public void DataGrid1_Delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.sqlCommand3.Parameters["@ID"].Value=this.DataGrid1.DataKeys[(int)e.Item.ItemIndex];
this.sqlCommand3.ExecuteNonQuery();
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(dataSet11,"BasicInformation");
this.DataGrid1.DataBind();
}

public void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=-1;
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(dataSet11,"BasicInformation");
this.DataGrid1.DataBind();
}

public void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.sqlCommand4.Parameters["@Name"].Value=this.DataGrid1.Items[(int)e.Item.ItemIndex].FindControl("Name");
this.sqlCommand4.Parameters["@Class"].Value=this.DataGrid1.Items[(int)e.Item.ItemIndex].FindControl("Class");
this.sqlCommand4.Parameters["@ID"].Value=this.DataGrid1.Items[(int)e.Item.ItemIndex].FindControl("ID");
this.sqlCommand4.Parameters["@PassWord"].Value=this.DataGrid1.Items[(int)e.Item.ItemIndex].FindControl("ID");
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(dataSet11,"BasicInformation");
this.DataGrid1.DataBind();
}


我在设计器里为DataGrid添加了2个模板列,分别是删除和编辑列,现在的问题是不能触发DataGrid里的事件,比如DeleteCommand,EditCommand等事件!!
望高手指点!!!
谢了!!!
Bright1982 2002-08-13
  • 打赏
  • 举报
回复
我已经是江郎才尽了!各种手段我都试过了,还事没有用!5555555555555555555555~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
老板要来检查了,我非常着急!
下面把所有代码都贴出,请各位大虾帮帮忙!


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 DataBase
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlCommand sqlCommand1;
protected System.Web.UI.WebControls.TextBox TextBoxName;
protected System.Web.UI.WebControls.TextBox TextBoxClass;
protected System.Web.UI.WebControls.TextBox TextBoxID;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Button Button1;
protected System.Data.SqlClient.SqlCommand sqlCommand2;
protected System.Data.SqlClient.SqlCommand sqlCommand3;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected DataBase.DataSet1 dataSet11;
protected System.Data.SqlClient.SqlCommand sqlCommand4;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
this.sqlConnection1.Open();
/*ButtonColumn del=new ButtonColumn();
EditCommandColumn edit=new EditCommandColumn();
del.CommandName="Delete";
del.Text="Delete";
del.ButtonType=System.Web.UI.WebControls.ButtonColumnType.PushButton;
this.DataGrid1.Columns.AddAt(0,del);
edit.EditText="Edit";
edit.CancelText="Cancel";
edit.UpdateText="Save";
edit.ButtonType=System.Web.UI.WebControls.ButtonColumnType.PushButton;
this.DataGrid1.Columns.AddAt(1,edit);*/


this.sqlDataAdapter1.Fill(dataSet11,"BasicInformation");
//this.DataGrid1.DataSource=dataSet11.Tables["BasicInformation"].DefaultView;
this.DataGrid1.DataBind();
}

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

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlCommand3 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlCommand4 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new DataBase.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.Button1.Click += new System.EventHandler(this.Button1_Click);
//
// sqlCommand3
//
this.sqlCommand3.CommandText = "DELETE FROM BasicInformation WHERE (ID = @ID)";
this.sqlCommand3.Connection = this.sqlConnection1;
this.sqlCommand3.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.NVarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source=Bright;initial catalog=Student;integrated security=SSPI;persist secur" +
"ity info=False;user id=lml;workstation id=BRIGHT;packet size=4096";
//
// sqlCommand2
//
this.sqlCommand2.CommandText = "INSERT INTO BasicInformation (Name, Class, ID, PassWord) VALUES (@Name, @Class, @" +
"ID, @PassWord)";
this.sqlCommand2.Connection = this.sqlConnection1;
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 50, "Name"));
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Class", System.Data.SqlDbType.NVarChar, 50, "Class"));
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.NVarChar, 50, "ID"));
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PassWord", System.Data.SqlDbType.NVarChar, 50, "PassWord"));
//
// sqlCommand1
//
this.sqlCommand1.CommandText = "SELECT NAME, CLASS, ID FROM BasicInformation";
this.sqlCommand1.Connection = this.sqlConnection1;
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlCommand3;
this.sqlDataAdapter1.InsertCommand = this.sqlCommand2;
this.sqlDataAdapter1.SelectCommand = this.sqlCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "BasicInformation", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("Name", "Name"),
new System.Data.Common.DataColumnMapping("Class", "Class"),
new System.Data.Common.DataColumnMapping("ID", "ID"),
new System.Data.Common.DataColumnMapping("PassWord", "PassWord")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlCommand4;
//
// sqlCommand4
//
this.sqlCommand4.CommandText = "UPDATE BasicInformation SET Name = @Name, Class = @Class, ID = @ID, PassWord = @I" +
"D";
this.sqlCommand4.Connection = this.sqlConnection1;
this.sqlCommand4.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 50, "Name"));
this.sqlCommand4.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Class", System.Data.SqlDbType.NVarChar, 50, "Class"));
this.sqlCommand4.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.NVarChar, 50, "ID"));
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
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_Delete);
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();

}
#endregion

Bright1982 2002-08-13
  • 打赏
  • 举报
回复
我已经是江郎才尽了!各种手段我都试过了,还事没有用!5555555555555555555555~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
老板要来检查了,我非常着急!
下面把所有代码都贴出,请各位大虾帮帮忙!


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 DataBase
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlCommand sqlCommand1;
protected System.Web.UI.WebControls.TextBox TextBoxName;
protected System.Web.UI.WebControls.TextBox TextBoxClass;
protected System.Web.UI.WebControls.TextBox TextBoxID;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Button Button1;
protected System.Data.SqlClient.SqlCommand sqlCommand2;
protected System.Data.SqlClient.SqlCommand sqlCommand3;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected DataBase.DataSet1 dataSet11;
protected System.Data.SqlClient.SqlCommand sqlCommand4;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
this.sqlConnection1.Open();
/*ButtonColumn del=new ButtonColumn();
EditCommandColumn edit=new EditCommandColumn();
del.CommandName="Delete";
del.Text="Delete";
del.ButtonType=System.Web.UI.WebControls.ButtonColumnType.PushButton;
this.DataGrid1.Columns.AddAt(0,del);
edit.EditText="Edit";
edit.CancelText="Cancel";
edit.UpdateText="Save";
edit.ButtonType=System.Web.UI.WebControls.ButtonColumnType.PushButton;
this.DataGrid1.Columns.AddAt(1,edit);*/


this.sqlDataAdapter1.Fill(dataSet11,"BasicInformation");
//this.DataGrid1.DataSource=dataSet11.Tables["BasicInformation"].DefaultView;
this.DataGrid1.DataBind();
}

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

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlCommand3 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlCommand4 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new DataBase.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.Button1.Click += new System.EventHandler(this.Button1_Click);
//
// sqlCommand3
//
this.sqlCommand3.CommandText = "DELETE FROM BasicInformation WHERE (ID = @ID)";
this.sqlCommand3.Connection = this.sqlConnection1;
this.sqlCommand3.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.NVarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source=Bright;initial catalog=Student;integrated security=SSPI;persist secur" +
"ity info=False;user id=lml;workstation id=BRIGHT;packet size=4096";
//
// sqlCommand2
//
this.sqlCommand2.CommandText = "INSERT INTO BasicInformation (Name, Class, ID, PassWord) VALUES (@Name, @Class, @" +
"ID, @PassWord)";
this.sqlCommand2.Connection = this.sqlConnection1;
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 50, "Name"));
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Class", System.Data.SqlDbType.NVarChar, 50, "Class"));
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.NVarChar, 50, "ID"));
this.sqlCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PassWord", System.Data.SqlDbType.NVarChar, 50, "PassWord"));
//
// sqlCommand1
//
this.sqlCommand1.CommandText = "SELECT NAME, CLASS, ID FROM BasicInformation";
this.sqlCommand1.Connection = this.sqlConnection1;
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlCommand3;
this.sqlDataAdapter1.InsertCommand = this.sqlCommand2;
this.sqlDataAdapter1.SelectCommand = this.sqlCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "BasicInformation", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("Name", "Name"),
new System.Data.Common.DataColumnMapping("Class", "Class"),
new System.Data.Common.DataColumnMapping("ID", "ID"),
new System.Data.Common.DataColumnMapping("PassWord", "PassWord")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlCommand4;
//
// sqlCommand4
//
this.sqlCommand4.CommandText = "UPDATE BasicInformation SET Name = @Name, Class = @Class, ID = @ID, PassWord = @I" +
"D";
this.sqlCommand4.Connection = this.sqlConnection1;
this.sqlCommand4.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.NVarChar, 50, "Name"));
this.sqlCommand4.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Class", System.Data.SqlDbType.NVarChar, 50, "Class"));
this.sqlCommand4.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.NVarChar, 50, "ID"));
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
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_Delete);
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();

}
#endregion

yohomonkey 2002-08-05
  • 打赏
  • 举报
回复
我是说控件的"autopostback"属性,设置了该属性后就可以接受你的处发事件.
如果你的控件是自己作的,可以添加你需要的事件和属性,来满足要求.

关于控件的"autopostback"属性设置,是在html脚本中可以找到的,
在"datagrid"的runat=server后面加上控件的"autopostback"属性=true.
Bright1982 2002-08-03
  • 打赏
  • 举报
回复
TO yohomonkey(ht):
  我的事件是在设计器里声明的,并不是我自己写的!
还有,我也没有找到autopostback这个属性!

请进一步指点!
谢谢!
Bright1982 2002-08-03
  • 打赏
  • 举报
回复
我是在WEB应用程序中使用的DataGrid,没有OnUpdateCommand,OnCancelCommand, OnEditCommand这些属性,只有UpdateCommand,CancelCommand, EditCommand这些事件!

我已经添加了这些事件了,如下:
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_Delete);

但是只有EditCommand事件可以触发!!!
这是为什么呢???
yohomonkey 2002-08-03
  • 打赏
  • 举报
回复
还有!
你的控件,有没有autopostback=true????
yohomonkey 2002-08-03
  • 打赏
  • 举报
回复
其事不用使用你自己定义的事件来处发!
datagrid本身就有这些事件啊(代码中选中datagrid,右边事件中会有.)!
datagridname.editcommand...........
除非是要使用脚本的情况,才需要自己写.

你后面的情况是你的代码问题:
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
注意,如果是自定义的事件,应该使用:
public Sub DataGridEdit(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
再试试!
spring_ok 2002-08-02
  • 打赏
  • 举报
回复
在datagrid的属性里要指定邦定的事件代码才可以的。
<asp:datagrid id="DataGrid1" runat="server" DataKeyField="GroupID" AutoGenerateColumns="false" OnUpdateCommand="DataGrid1_Update" OnCancelCommand="DataGrid1_Cancel" OnEditCommand="DataGrid1_Edit" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana" CellPadding="3" BorderWidth="1" BorderColor="black" OnSortCommand="DataGrid1_Sort" AllowSorting="true" OnPageIndexChanged="DataGrid1_Page" AllowPaging="true" OnItemDataBound="DataGrid1_ItemDataBound" PagerStyle-HorizontalAlign="Center" PagerStyle-NextPageText="Next" PagerStyle-PrevPageText="Prev">
<Columns>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" HeaderText="Edit Group" HeaderStyle-Wrap="False" ItemStyle-VerticalAlign="Top"></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText="Del" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:HyperLink Runat="server" ID="HyperLink1" NavigateUrl='<%# "GroupMan.aspx?Act=Del&GroupID=" + DataBinder.Eval(Container.DataItem, "GroupID") %>'>Del</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Group ID" ReadOnly="True" DataField="GroupID" SortExpression="GroupID" HeaderStyle-Wrap="false" ItemStyle-VerticalAlign="Top"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Group Name" SortExpression="GroupName" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "GroupName") %>' ID="Label1" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" id="Edit_GroupName" Text='<%# DataBinder.Eval(Container.DataItem, "GroupName") %>' Columns="40" MaxLength="100"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Sort Order" SortExpression="SortOrder" HeaderStyle-Wrap="False" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SortOrder") %>' ID="Label2" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" id="Edit_SortOrder" Text='<%# DataBinder.Eval(Container.DataItem, "SortOrder") %>' Columns="4" />
<br>
<asp:CompareValidator Runat="server" ID="cvSortOrder" ControlToValidate="Edit_SortOrder" Operator="DataTypeCheck" Type="Integer" ErrorMessage="Must be a number" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Remark" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Remark") %>' ID="Label3" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" id="Edit_Remark" Text='<%# DataBinder.Eval(Container.DataItem, "Remark") %>' Columns="30" Rows="4" TextMode="MultiLine" />
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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