Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 .
Posted
Updated 31-Oct-12 3:18am
v2

I Found the error i added this sentence EnableEventValidation="False" to the page tag and it worked ! =D
 
Share this answer
 
First Grid Template Field :

ASP.NET
<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.NET
<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
VB
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


The rowEditing for the first Grid


VB
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


The rowEditing for the Second Grid
VB
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

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
 
Share this answer
 
v3
what ever .cs code u wrote for first grid u should write for second grid .
like

C#
protected void gv1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
   {}
 protected void gv2_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
}
 
Share this answer
 
Comments
ayat abukhadra 3-Oct-12 9:35am    
I did the full code is different but still not working its not recognizing the second grid templateField buttons as they got commandnames I've tried to just show a msgbox on the row command function for the second grid but it didn't even enter that code
solanki.net 3-Oct-12 23:54pm    
can u send your code ?
ayat abukhadra 4-Oct-12 2:43am    
I'm gonna post it as a solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900