datagrid的问题

ctbgjm 2003-10-16 03:18:45
源码:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test10.aspx.vb" Inherits="WebApplication1.test10"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>test10</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DG" OnEditCommand="DG_ItemCommand" AutoGenerateColumns=False CellPadding=4 runat="server"> <!--出错地方-->
<Columns>
<asp:BoundColumn HeaderText="Book Title" DataField="Title"></asp:BoundColumn>
<asp:ButtonColumn CommandName="select" Text="Select!"></asp:ButtonColumn>
<asp:ButtonColumn CommandName="unselect" Text="Unselect!"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
----------------------------------------
Imports System.Data.SqlClient

Public Class test10
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents DG As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
Dim con As SqlConnection
Dim com As SqlCommand
con = New SqlConnection("server=samsung;user id=sa;password=;database=pubs;connection reset=false")
com = New SqlCommand("select * from Titles", con)
con.Open()
DG.DataSource = com.ExecuteReader()
DG.DataBind()
con.Close()
End If
End Sub

Private Sub DG_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.ItemCommand
If e.CommandName = "select" Then
e.Item.BackColor = System.Drawing.Color.LightGreen
e.Item.Font.Bold = True
Else
e.Item.BackColor = System.Drawing.Color.White
e.Item.Font.Bold = False
End If
End Sub
End Class
--------------------------------------------------
出错原因:
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: BC30456: 'dg_edit' is not a member of 'ASP.test10_aspx'.

请问是什么原因?谢谢

...全文
26 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
houlinghouling 2003-10-16
  • 打赏
  • 举报
回复
(1)你的datagrid 的id ="DG",你是不是在.cs文件中写成了'dg_edit'
(2)你的edit是不是应该有一个模板列,而且方法应该是protected or public
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="cmdEdit" Runat="server" CommandName="Edit" text="修改" CssClass="login-link01"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="cmdCancel" Runat="server" CommandName="Cancel" text="取消" CssClass="login-link01"></asp:LinkButton>
<asp:LinkButton id="cmdUpdate" Runat="server" CommandName="Update" text="更新" CssClass="login-link01"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>


protected Sub DG_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DG.ItemCommand
If e.CommandName = "select" Then
e.Item.BackColor = System.Drawing.Color.LightGreen
e.Item.Font.Bold = True
Else
e.Item.BackColor = System.Drawing.Color.White
e.Item.Font.Bold = False
End If
End Sub

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧