 |
|
ASP.NET GridView Event Double Click (แถวไหนก็ได้ คอลัมภ์ไหนก็ได้) เขียนอย่างไร? |
|
 |
|
|
 |
 |
|
ผมรู้ว่ามันยาก (TOP 10) ตอนนี้ผม งม มาถึงตรงนี้
document.querySelector('.gridViewClassName).id
|
 |
 |
 |
 |
Date :
2013-02-28 10:18:46 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมไม่ได้บอกรายละเอียด ข้อยกเว้น อทิเช่น Event
----- grdView.SelectedIndexChanging
----- grdView.SelectedIndexChanged
---------- สองอีเวนต์ข้างบน มันทำงานช้า/ช้ามากฯ ไม่ทันใจ (พูดง่ายฯ ใช้งานจริงไม่ได้เลย)
|
 |
 |
 |
 |
Date :
2013-02-28 10:36:21 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กระทู้นี้สอน ผ่านมา ใช้ GridView SelectedIndexChanged ดีแต่
แต่ event นี้ โดยตัวมันเอง มันไม่ postback
เราเลยต้องใช้ javascript ไป call __dopostback มาใช้

MyGridView.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="MyGridView.aspx.vb" Inherits="MyGridView" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="Both" AutoGenerateColumns="false">
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<SelectedRowStyle BackColor="#D1DDF1" ForeColor="#333333" />
<Columns>
<asp:BoundField HeaderText="#" DataField="ID" />
<asp:BoundField HeaderText="Name" DataField="Name" />
</Columns>
</asp:GridView>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
MyGridView.aspx.vb
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 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
TO ห้ามตอบเกินวันละ 2 กระทู้ (เป็นคนมีน้ำใจ/หรือเปล่า)
แต่ผมชอบนะ
กระผมขอบคุณมากครับ ด้วยใจจริง
ผ่านมา
ปล. ผมไม่เคยจะขอบคุณใครง่ายฯ เพราะผมผ่านมาร้อยเอ็ดเจ็ดย่านน้ำ
หลานสาวของผม จบ ป.โท จบ. ดร. เป็นอาจารย์ อยู่มหาวิทยาลัยชื่อดัง หลายฯคน
ผมไม่เคยยกมือไหว้ ลูก หลาน ของผม
|
 |
 |
 |
 |
Date :
2013-02-28 23:01:48 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
MyGridView.aspx
MyGridView.aspx.vb
ใช้งานจริงไม่ได้เลย
|
 |
 |
 |
 |
Date :
2013-02-28 23:03:30 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
MyGridView.aspx
MyGridView.aspx.vb
เอาไว้หลอก อาจารย์ ที่สอนตามมหาวิทยาลัยในประเทศไทย (ทั้งหมด)
พอได้ เกรด 4 (เกียตินิยม)
|
 |
 |
 |
 |
Date :
2013-02-28 23:08:41 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นไรมากไหมลูก
เซ็งโลกก็หาหนังโป๊มาดูซะนะ จะได้ไม่เป็นภาระลูกหลาน 
|
 |
 |
 |
 |
Date :
2013-03-01 10:35:01 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
+55555
ปล. Like +5
|
 |
 |
 |
 |
Date :
2013-03-01 11:32:54 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|