Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        s = WebConfigurationManager.ConnectionStrings["ChartDatabaseConnectionString"].ConnectionString;
        con = new SqlConnection(s);
        con.Open();
        cmd = new SqlCommand();
        cmd = new SqlCommand("delete from Employee where employee_name='", con);
        cmd.ExecuteNonQuery();
        con.Close();
        Label1.Text = " Record Deleted successfully";
        clearData();
    }
}


XML
Reply Modify the comment.  Delete the comment.
source code



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Gridview.aspx.cs" Inherits="Gridview" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" OnRowDeleted="GridView1_RowDeleted" OnRowEditing="GridView1_RowEditing">

<asp:TemplateField HeaderText="EmployeeID">

<asp:Label ID="Lbl1EmployeeName" runat="server" Text='<%# Eval("EmployeeID") %>'>


<asp:TemplateField HeaderText="EmployeeName">

<asp:Label ID="Lbl2EmployeeName" runat="server" Text='<%# Eval("EmployeeName") %>'>


<asp:TemplateField HeaderText="Qualification">

<asp:Label ID="Lbl3Qualification" runat="server" Text='<%# Eval("Qualification") %>'>


<asp:TemplateField HeaderText="Gender">

<asp:Label ID="Lbl4Gender" runat="server" Text='<%# Eval("Gender") %>"'>


<asp:TemplateField HeaderText="Address">

<asp:Label ID="Lbl5Address" runat="server" Text='<%# Eval("Address") %>'>


<asp:TemplateField HeaderText="Operations">

<asp:Button ID="btnedit" runat="server" CommandName="btnedit" Height="35px" Text="Edit" Width="70px" />
<asp:Button ID="btndelete" runat="server" CommandName="btndelete" Height="35px" Text="Delete" Width="62px" />




Enter Employee Details



</div>
</form>
</body>
</html>








error is



Error 3 } expected E:\mine\WebSite8\Gridview.aspx.cs 25 10 WebSite8
Error 8 The name 'clearData' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs 36 9 WebSite8
Error 7 The name 'Label1' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs 35 9 WebSite8
Error 4 The name 's' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs 28 9 WebSite8
Error 6 The name 's' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs 29 33 WebSite8
Error 5 The name 'WebConfigurationManager' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs 28 13 WebSite8
Error 2 Type or namespace definition, or end-of-file expected E:\mine\WebSite8\Gridview.aspx.cs 39 1 WebSite8
Warning 1 Validation (XHTML5): Attribute 'align' is not a valid attribute of element 'table'. E:\mine\WebSite8\calculator.aspx 35 16 WebSite8
Posted
Updated 29-Jul-14 21:11pm
v3

1 solution

try this.. :)

1) The name 'clearData' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs


solution

You can remove clearData(); or make function having name clearData() like this... :)

C#
public void clearData() { 
        
        
        }


2)Error 7 The name 'Label1' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs

either you can out Label1 in your designer(aspx) page or you can remove it from your code

3) The name 's' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs

You have to defined it as a string like that

C#
string s = ConfigurationManager.ConnectionStrings["ChartDatabaseConnectionString"].ConnectionString;


4)The name 'WebConfigurationManager' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs


try this instead of 'WebConfigurationManager'
C#
string s = ConfigurationManager.ConnectionStrings["ChartDatabaseConnectionString"].ConnectionString;


try to justify your code with regular required paranthysis and try to explore solution by your self
 
Share this answer
 

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