<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="k.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="datagrid1" style="Z-INDEX: 101; LEFT: 88px; POSITION: absolute; TOP: 136px"
runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<FONT face="宋体"></FONT>
</HeaderTemplate>
<ItemTemplate>
<FONT face="宋体">
<TABLE id="Table1" style="WIDTH: 320px; HEIGHT: 192px" cellSpacing="1" cellPadding="1"
width="320" border="1">
<TR>
<TD style="WIDTH: 64px"><FONT face="宋体">正文</FONT></TD>
<TD colSpan="2"><%# Container.DataItem("name")%></TD>
</TR>
<TR>
<TD style="WIDTH: 64px"><FONT face="宋体">标题</FONT></TD>
<TD colSpan="2"><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"><%#Container.DataItem("text")%></FONT></TD>
</TR>
<TR>
<TD colSpan="3"><FONT face="宋体">
<asp:LinkButton id="edit" runat="server" CommandName="edit">编辑</asp:LinkButton>&nbsp;
<asp:LinkButton id="del" runat="server" CommandName="del">删除</asp:LinkButton></FONT></TD>
</TR>
</TABLE>
</FONT>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>-------------------------------------------------------------Imports System.Data
Imports System.Data.OleDb
Public Class WebForm1
    Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      databind()..........End SubPrivate Sub DataGrid1_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
        If e.CommandName = "edit" Then
            Response.Write("edit item")
        End If        If e.CommandName = "del" Then
            Response.Write("del item")
        End If
    End Sub
End Class
为什么我点 编辑或删除 按钮没有反应呢?! 照MSDN做的 弄不明白了``谢谢

解决方案 »

  1.   

    If e.CommandName = "edit" Then
    ?是不是应该修改称 If e.CommandName.ToLower() = "edit" Then
      

  2.   

    是不是CommandName没有设对呀,还是没有时间句柄
      

  3.   

    代码没有什么问题,看一看你是否private void InitializeComponent()中有ItemCommand
    如果还是不可以,你就在.aspx中的datagrid中加上次事件
      

  4.   

    If e.CommandName = "Edit" Then
                Response.Write("edit item")
            End If        If e.CommandName = "Delete" Then
                Response.Write("del item")
            End If或者就直接用DeleteCommand事件和EditCommand事件
      

  5.   

    参见MSDN:ms-help://MS.NETFrameworkSDKv1.1.CHS/cpref/html/frlrfsystemwebuiwebcontrolsdatagridclassitemcommandtopic.htm
      

  6.   

    <asp:LinkButton id="edit" runat="server" CommandName="edit">编辑</asp:LinkButton>我用的是小写呀?
      

  7.   

    TO; jeffidea(程序诗人) 
    该页无法显示
      

  8.   

    报告 : houlinghouling(秋水伊) 
    private void InitializeComponent()中有ItemCommand
    请问 次事件 指的是什么?!
      

  9.   

    有没有句柄
    this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);?
      

  10.   

    我初学 问的可能有点弱Private Sub DataGrid1_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)是句柄吗? C#不太熟悉
      

  11.   

    在   Private Sub DataGrid1_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)   的後面加
      Handles DataGrid1.ItemCommand
      

  12.   

    你从头再来一次:
    1.拖DataGrid
    2.数据库绑定
    3.属性生成器-〉列-〉添加修改和删除两个按钮
    4.DataGrid的ItemCommand事件中写入
    If e.CommandName = "Edit" Then
                Response.Write("edit item")
            End If        If e.CommandName = "Delete" Then
                Response.Write("del item")
            End If
    不行你揍我!