如果是WINDOWS应用程序,是ONCLICK事件,如果是网页什么都没有

解决方案 »

  1.   

    winForm中是ONCLICK事件
    也可以用onMouseDown 事件
    要得到点击的行的话
    用hitTest
      

  2.   

    给你个例子看一看
      下面的代码实现了如何得到点击的当前行的数据
          GetCurrentClickRow.aspx
    <%@ Page Language="vb" EnableViewState="False" AutoEventWireup="false" 
     Codebehind="GetCurrentClickRow.aspx.vb" Inherits="aspxWeb.mengxianhui.com.GetCurrentClickRow"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
      <HEAD>
        <title>GetCurrentClickRow</title>
        <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
        <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      </HEAD>
      <body style="FONT-SIZE: 9pt" MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
          <asp:Panel id="Panel1" runat="server">
            <asp:Label id="label1" Runat="server"></asp:Label>
            <asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" CellPadding="4"
            BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CC9966">
              <ItemStyle ForeColor="#330099" BackColor="White" Font-Size="9pt"></ItemStyle>
              <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000" Font-Size="9pt"></HeaderStyle>
              <Columns>
                <asp:BoundColumn DataField="Title"></asp:BoundColumn>
                <asp:BoundColumn DataField="CreateDate"></asp:BoundColumn>
              </Columns>
            </asp:DataGrid>
          </asp:Panel>
        </form>
      </body>
    </HTML>
    GetCurrentClickRow.aspx.vb
    Imports System
    Imports System.Data
    Imports System.Data.OleDbPublic Class GetCurrentClickRow
      Inherits System.Web.UI.Page
      Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
      Protected WithEvents label1 As System.Web.UI.WebControls.Label
      Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#Region " Web Form Designer Generated Code "
      <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
      End Sub  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) _
       Handles MyBase.Init
        InitializeComponent()
      End Sub#End Region  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
       Handles MyBase.Load
        label1.Text = "获得所点击行的例子"
        label1.Font.Bold = True
        Panel1.HorizontalAlign = HorizontalAlign.Center
        DataGrid1.Columns(0).HeaderText = "文章标题"
        DataGrid1.Columns(1).HeaderText = "发布时间"
        DataGrid1.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
        DataGrid1.AlternatingItemStyle.BackColor = System.Drawing.Color.Ivory
        DataGrid1.HorizontalAlign = HorizontalAlign.Center
        Dim cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
         + Server.MapPath("Test.mdb")
        Dim cn As New OleDbConnection(cnString)
        cn.Open()
        Dim strSQL As String = "SELECT TOP 10 Title,CreateDate FROM Document ORDER BY CreateDate DESC"
        Dim cmd As New OleDbCommand(strSQL, cn)
        DataGrid1.DataSource = cmd.ExecuteReader
        DataGrid1.DataBind()
        cn.Close()
        cn.Dispose()
        cn = Nothing
      End Sub  Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
     ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
          e.Item.Attributes.Add("onclick", "this.style.backgroundColor='#FFCC66';alert('您点击的是:\n\n第" _
     + e.Item.ItemIndex.ToString() + "行\n\n文章标题是:" + e.Item.Cells(0).Text.Replace(",", "\'") + "')")
          e.Item.Cells(1).Text = Format(System.Convert.ToDateTime(e.Item.Cells(1).Text.ToString()), "yyyy年M月d日")
          If e.Item.Cells(0).Text.Length > 30 Then
            e.Item.Attributes.Add("Title", e.Item.Cells(0).Text)
            e.Item.Cells(0).Text = e.Item.Cells(0).Text.Substring(0, 28) + "…"
          End If
        End If
      End SubEnd Class
      

  3.   

    datagrid在页面其实就是一个table,可以通过写客户端脚本得到绑定到datagrid的数据源(datatable)的行索引,写入一个隐藏表单,再submit一下在后台程序处理就可以了。