我在gridview中遇到错误 [英] iam getting error in gridview
问题描述
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();
}
}
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>
错误是
错误3}预期E:\mine\WebSite8 \ GridView.aspx.cs 25 10 WebSite8
错误8当前上下文中不存在名称'clearData'E:\mine \WebSite8 \ GridView.aspx.cs 36 9 WebSite8
错误7名称'Label1'不存在于目前的背景E:\ tom WebSite8 \ GridView.aspx.cs 35 9 WebSite8
错误4当前上下文中名称''不存在E:\mine\WebSite8 \ GridView.aspx.cs 28 9 WebSite8
错误6当前上下文中名称''不存在E:\mine\WebSite8 \ GridView.aspx.cs 29 33 WebSite8
错误5当前上下文中不存在名称WebConfigurationManagerE:\mine \WebSite8 \ GridView.aspx.cs 28 13 WebSite8
错误2类型或命名空间定义,或结束-file expected E:\mine \WebSite8 \ GridView.aspx.cs 39 1 WebSite8
警告1验证(XHTML5):属性'align'不是元素'table'的有效属性。 E:\mine \WebSite8 \ calculator.aspx 35 16 WebSite8
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
推荐答案
试试这个.. :)
1)当前上下文中不存在clearData这个名称E:\\\ n \\\\\\\\\\\\\\\\\\\\\\\ br $>
解决方案
您可以删除clearData();
或使函数具有名称clearData()
喜欢这个...... :)
try this.. :)
1) The name 'clearData' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs
solution
You can removeclearData();
or make function having nameclearData()
like this... :)
public void clearData() {
}
2)错误7当前上下文中不存在名称Label1E:\mine\WebSite8 \ GridView.aspx.cs
您可以在设计器(aspx)页面中输出Label1,也可以从代码中删除它
3)当前上下文中名称's'不存在E:\mine\WebSite8 \\ Gridview.aspx.cs
您必须将其定义为类似的字符串
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
string s = ConfigurationManager.ConnectionStrings["ChartDatabaseConnectionString"].ConnectionString;
4)当前上下文中不存在名称WebConfigurationManagerE:\mine \\ \ nWebSite8 \ GridView.aspx.cs
试试这个而不是' WebConfigurationManager
'
4)The name 'WebConfigurationManager' does not exist in the current context E:\mine\WebSite8\Gridview.aspx.cs
try this instead of 'WebConfigurationManager
'
string s = ConfigurationManager.ConnectionStrings["ChartDatabaseConnectionString"].ConnectionString;
尝试证明你的代码是正确的经常需要的paranthysis并尝试通过自己探索解决方案
try to justify your code with regular required paranthysis and try to explore solution by your self
这篇关于我在gridview中遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!