Imports System.Data
Partial Class MyGridView
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
GridView1.DataSource = GetData()
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
//ตรงนี้เปลี่ยนจาก onclick เป็น ondblclick ซะ
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(DirectCast(sender, GridView), String.Format("Select${0}", e.Row.RowIndex.ToString())))
e.Row.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor='#EFF3FB'; this.style.cursor='pointer'")
e.Row.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor='#FFFFFF';")
End If
End Sub
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim Gv As GridView = DirectCast(sender, GridView)
Gv.SelectedRow.Attributes.Clear()
If Gv.SelectedIndex >= 0 Then
Label1.Text = String.Format("Row Index: {0}", Gv.SelectedIndex.ToString())
End If
End Sub
Protected Function GetData() As DataTable
Dim data As New DataTable()
data.Columns.Add(New DataColumn("ID", GetType(String)))
data.Columns.Add(New DataColumn("Name", GetType(String)))
For i As Integer = 1 To 5
Dim dr As DataRow = data.NewRow()
dr("ID") = String.Format("{0}.", i.ToString())
dr("Name") = String.Format("ผ่านมา_{0}", i.ToString())
data.Rows.Add(dr)
Next
Return data
End Function
End Class
Date :
2013-02-28 13:25:46
By :
ห้ามตอบเกินวันละ 2 กระทู้
No. 4
Guest
TO ห้ามตอบเกินวันละ 2 กระทู้ (เป็นคนมีน้ำใจ/หรือเปล่า)
แต่ผมชอบนะ