Spini in

Spini in

  • NA
  • 4
  • 3.1k

How to solve the compiler error CS1061 'GridView1_RowCommand'

May 3 2021 12:08 PM
My PROBLEM: my local machine, it's working perfectly but when I uploaded it to my domain, an error occurred.
 
Compilation Error
 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
 
Compiler Error Message: CS1061: 'ASP.customerregister_aspx' does not contain a definition for 'GridView1_RowCommand' and no extension method 'GridView1_RowCommand' accepting a first argument of type 'ASP.customerregister_aspx' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 322: <td > Line 323: <asp:Label ID="Nodata" runat ="server" Visible="false" Text="please add the data" ForeColor ="Red" Font-Bold ="true" Font-Size ="X-Large"></asp:Label> Line 324: <asp:GridView ID="GridView1" Class="myGridClass" runat="server" AutoGenerateColumns="false" HorizontalAlign="Right" PageSize="10" AllowPaging="true" OnPageIndexChanging="OnPaging" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="ID"> Line 325: <RowStyle CssClass="gridCSS" /> Line 326: <AlternatingRowStyle CssClass="gridAlternateCSS" />
 
What I have tried
 
Frontend code:
  1. <asp:GridView ID="GridView1" Class="myGridClass" runat="server" AutoGenerateColumns="false" HorizontalAlign="Right" PageSize="10" AllowPaging="true" OnPageIndexChanging="OnPaging" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="ID">   
  2. <RowStyle CssClass="gridCSS" />   
  3. <AlternatingRowStyle CssClass="gridAlternateCSS" />   
  4. <HeaderStyle CssClass="gridCSS" />   
  5. <Columns>   
  6. <asp:BoundField DataField="ID" HeaderText="ID" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true" /> <asp:BoundField DataField="CustomerName" HeaderText="Customer Name" HeaderStyle-Width ="100px" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true" />   
  7. <asp:BoundField DataField="Date" HeaderText="Date" DataFormatString ="{0:dd/MM/yyyy}" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true" />   
  8. <asp:BoundField DataField="withdepositconnection" HeaderText="With Dep Conn" HeaderStyle-Width ="50px" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true" />   
  9. <asp:BoundField DataField="zerodepositconnection" HeaderText="Zero Dep Conn" HeaderStyle-Width ="50px" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true" />   
  10. <asp:BoundField DataField="OpenCylinderbalance" HeaderText="Opn Cyl Bal" HeaderStyle-Width ="50px" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true" />   
  11. <asp:BoundField DataField="AmountDebit" HeaderText="Debit Amt" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true" />   
  12. <asp:BoundField DataField="AmountCredit" HeaderText="Credit Amt" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true"/>   
  13. <asp:TemplateField HeaderText="Edit Details" ControlStyle-Font-Bold="true" ControlStyle-ForeColor="Black" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true">   
  14. <ItemTemplate>  
  15.  <asp:LinkButton ID="lnkview" runat="server" CssClass="gridCSS" ForeColor="green" Font-Bold="true" CommandArgument='<%# Eval("ID") %>' OnClick="lnk_OnClick">Edit</asp:LinkButton>   
  16.  <%-- <asp:ImageButton ID="ImageButton1" ImageUrl="~/images/edit-icon.png" runat="server" Width="15" Height="15" CommandArgument='<%# Eval("ID") %>' OnClick="lnk_OnClick" CausesValidation="false"/>--%>   
  17.  </ItemTemplate>   
  18.  </asp:TemplateField>   
  19.  <asp:TemplateField HeaderText="Delete" ShowHeader="False" HeaderStyle-Font-Names="center" HeaderStyle-Font-Size="Small" HeaderStyle-Font-Bold="true">   
  20.  <ItemTemplate>   
  21.  <asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="javascript: return confirm('Do you want to delete Customer this record?')" CommandArgument='<%# Eval("ID") %>' Text="Delete"></asp:LinkButton>   
  22.  </ItemTemplate>   
  23.  </asp:TemplateField>   
  24.  </Columns>   
  25.  </asp:GridView>
Backend code:
  1. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {  
  2.   int ID = Convert.ToInt32(e.CommandArgument.ToString());  
  3.   if (e.CommandName == "Delete") {  
  4.     if (sqlCon.State == ConnectionState.Open) {  
  5.       sqlCon.Close();  
  6.     }  
  7.     sqlCon.Open();  
  8.     SqlCommand sqlCmd = new SqlCommand();  
  9.     sqlCmd.Connection = sqlCon;  
  10.     sqlCmd.CommandText = "Delete from CustomerRegistration where ID=" + ID + "";  
  11.     sqlCmd.ExecuteNonQuery();  
  12.     sqlCmd.Dispose();  
  13.     sqlCon.Close();  
  14.     GridView1.DataBind();  
  15.   }  
  16. }  
  17. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { //  
  18. int index = Convert.ToInt32(e.RowIndex); //  
  19. DataTable dt = ViewState["dt"as DataTable; //  
  20. dt.Rows[index].Delete(); //  
  21. ViewState["dt"] = dt; //  
  22. GridView1.DataSource = dtbl; GridView1.DataBind(); }   
  23. protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { }  

Answers (1)