Get the current line you click in DataGrid

xiaoxiao2021-03-05  20

The following code implements the program code data GetCurrentClickRow.aspx how to get the click of the current line <% @ Page Language = "vb" EnableViewState = "False" AutoEventWireup = "false" Codebehind = "GetCurrentClickRow.aspx.vb" Inherits = "aspxWeb .mengxianhui.com.getcurrentClickRow "%>

GetCurrentClickRow

GetCurrentClickRow.aspx.vb Imports System Imports System.Data Imports System.Data.OleDb Public 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"

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 = "Get the example of the right line" Label1.Font.Bold = True Panel1.horizontalalign = horizontalalign.center DataGrid1.columns (0) .Headertext = "Article Title" DataGrid1.Columns (1) .HeaderText = "published" 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.data Bind () 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 = ListiteM.Item THEN E.Item.attributes.add ("onclick", "this.style.backgroundColor = '# ffcc66'; Alert ('You click: / n / N "_ E.Item.itemindex.tostring () " row / n / n] Title is: " E.Item.cells (0) .text.replace (", ",", "/ '") "')") E.Item.cells (1) .text =

转载请注明原文地址:https://www.9cbs.com/read-37928.html

New Post(0)