两个带有按钮的GridView具有命令名 [英] Two GridView with Buttons have commandnames
问题描述
你好,
我正在尝试创建具有相同功能的两个网格视图,但是页脚会有所不同.我已经复制并粘贴了第一个网格视图,更改了第二个网格视图的ID并运行它,但是命令名适用于第一个一个而不是第二个?为什么我的第二个GridView不采用已创建按钮的命令名?
注意:我的按钮是templatefield.
Hello,
I''m trying to create two grid-views with the same functionality but the footer would be different I''ve copied and pasted the first grid view , changed the id for the second one and run it but the commandname worked for the first one but not for the second one ? why my second GridView is not taking commandnames for the created buttons ?
Note: My buttons are templatefield .
推荐答案
您为第一个网格编写的.cs代码应该为第二个网格编写.
就像
what ever .cs code u wrote for first grid u should write for second grid .
like
protected void gv1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{}
protected void gv2_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
}
第一个网格模板字段:
First Grid Template Field :
<asp:templatefield xmlns:asp="#unknown">
<edititemtemplate>
<<asp:Button ID="Update" runat="server" CommandName="Update" Text="Update" />
<<asp:Button ID="Cancel" runat="server"
ommandName="Cancel" Text="Cancel" />
</edititemtemplate>
<itemtemplate>
<<asp:Button ID="Edit" runat="server"
ommandName="Edit" Text="Edit" />
</itemtemplate>
<footertemplate>
<asp:button id="Insert" runat="server" commandname="Insert" text="Insert" />
</footertemplate>
</asp:templatefield>
第二个网格模板字段:
Second Grid Template Field:
<asp:templatefield xmlns:asp="#unknown">
<edititemtemplate>
<<asp:Button ID="UpdateS" runat="server" CommandName="Update" Text="Update" />
<<asp:Button ID="CancelS" runat="server"
ommandName="Cancel" Text="Cancel" />
</edititemtemplate>
<itemtemplate>
<<asp:Button ID="EditS" runat="server"
ommandName="Edit" Text="Edit" />
</itemtemplate>
<footertemplate>
<asp:button id="Search" runat="server" commandname="Insert" text="Insert" />
</footertemplate>
</asp:templatefield>
而且所有其他列都一样,除了我的页脚在控件类型上有所不同,但仍然没有代码,因此控件无所谓
我的加载函数
And all the other columsn are the same except my footer which is different in controls type but still has no code so the controls wont matter
my Load Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
''Do Connection and bring Data From Access DataBase
GridView1.DataSourse = DataSet1
GridView1.DataBind()
GridView2.DataSourse = DataSet1
GridView2.DataBind()
End Sub
第一个Grid的rowEditing
The rowEditing for the first Grid
Protected Sub GridView1_RowEditing(sender As Object, e As System.Wev.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
GridView1.DataSourse = DataSet1
GridView1.DataBind()
End Sub
第二个网格的rowEditing
The rowEditing for the Second Grid
Protected Sub GridView2_RowEditing(sender As Object, e As System.Wev.UI.WebControls.GridViewEditEventArgs) Handles GridView2.RowEditing
GridView2.EditIndex = e.NewEditIndex
GridView2.DataSourse = DataSet1
GridView2.DataBind()
End Sub
我已经解决了第一个问题,所以现在它可以识别编辑命令",但是在此之后,它将看不到其他按钮命令,例如update或cancel ..我通过将网格绑定到Page_load而不是按钮上的数据来解决了第一个问题单击,但是现在我需要在RowEditing级别进行绑定,这会带来问题,这是什么问题?
注意:一次只需要显示一个网格
I''ve solved the first problem so now it recognize the Edit Command but after that it wont see the other buttons command such as update or cancel .. i solved the first problem by binding the grid to the data at Page_load instead of a button click but now i need to bind at RowEditing level which makes a problem , what would be the problem ?
Note : Only one grid has to be shown at a time
我发现我在页面标记中添加了这句话EnableEventValidation ="False"的错误,它起作用了! = D
I Found the error i added this sentence EnableEventValidation="False" to the page tag and it worked ! =D
这篇关于两个带有按钮的GridView具有命令名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!