 |
|
checkbox to delete within gridview ทำการลบโดย เลือกจาก checkboxใน gridview แล้วกดปุ่ม delete แต่ทำยังงัย มันก้อไม่ยอมเข้าลูปเลยค่ะ |
|
 |
|
|
 |
 |
|
ลองทำตามแระค่ะพี่ มันerrorค่ะพี่วิน
Dim chkDel As CheckBox = CType(gvMagnetWireList.FindControl("chkMagnetRowID"), CheckBox)
Dim TextBox1 As TextBox = CType(gvMagnetWireList.FindControl("TextBox1"), TextBox)
If chkDel.Checked = True Then '- - - >error บรรทัดนี้น่ะพี่วิน
มันฟ้องว่า
System.NullReferenceException: Object reference not set to an instance of an object.
Line 325: ' Response.Write(i)
Line 326: ' If isChecked = True Then
Line 327: If chkDel.Checked = True Then
|
 |
 |
 |
 |
Date :
2010-06-04 13:28:35 |
By :
เนย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
debug ก้อไม่ได้ด้วย มันฟ้อง error
unable to connect to the asp.net development server
ใครเคยเจอแบบนี้บ้าง
โปรดส่งใครมาช่วยเนยทีนะ...
|
 |
 |
 |
 |
Date :
2010-06-04 13:50:00 |
By :
เนย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
การเขียนด้วย vb ทำให้ความน่าสนใจที่เข้ามาตอบลดลง

MyGridView.aspx
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="MyGridView.aspx.vb" Inherits="MyGridView" %>
<!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:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
MyGridView.aspx.vb
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Public Partial Class MyGridView
Inherits System.Web.UI.Page
Private dataSource As DataTable
Protected Sub Page_Init(sender As Object, e As EventArgs)
dataSource = New DataTable()
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs)
dataSource = If(ViewState("dataSource") IsNot Nothing, DirectCast(ViewState("dataSource"), DataTable), GetDataSource())
GridView1.DataSource = dataSource
Dim Index As New BoundField()
Index.HeaderText = "#"
Index.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
Index.ItemStyle.HorizontalAlign = HorizontalAlign.Right
Index.DataField = "ID"
Dim MonthName As New BoundField()
MonthName.HeaderText = "MonthName"
MonthName.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
MonthName.ItemStyle.HorizontalAlign = HorizontalAlign.Left
MonthName.DataField = "Month"
Dim DeleteButtom As New CommandField()
DeleteButtom.HeaderText = "Delete"
DeleteButtom.ButtonType = ButtonType.Image
DeleteButtom.ShowEditButton = False
DeleteButtom.ShowDeleteButton = True
DeleteButtom.DeleteImageUrl = "~/images/delete-16x16.png"
DeleteButtom.ItemStyle.HorizontalAlign = HorizontalAlign.Center
DeleteButtom.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
GridView1.AutoGenerateColumns = False
GridView1.DataKeyNames = New String() {"ID"}
If Not IsPostBack Then
ViewState("dataSource") = dataSource
GridView1.Columns.Add(Index)
GridView1.Columns.Add(MonthName)
GridView1.Columns.Add(DeleteButtom)
GridView1.DataBind()
End If
End Sub
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1_RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim DeleteButton As ImageButton = DirectCast(e.Row.Cells(2).Controls(0), ImageButton)
DeleteButton.OnClientClick = "javascript:return confirm('คุณต้องการลบข้อมูลนี้ใช่หรือไม่')"
End If
End Sub
Protected Sub GridView1_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GridView1.RowDeleting
dataSource.Rows(e.RowIndex).Delete()
dataSource.AcceptChanges()
GridView1.DataSource = dataSource
GridView1.DataBind()
ViewState("dataSource") = dataSource
End Sub
Private Function GetDataSource() As DataTable
Dim Dt As New DataTable()
Dt.Columns.Add(New DataColumn("ID", GetType(Integer)))
Dt.Columns.Add(New DataColumn("Month", GetType(String)))
For i As Integer = 1 To 12
Dim Dr As DataRow = Dt.NewRow()
Dr("ID") = i.ToString()
Dr("Month") = DateTime.Parse(String.Format("1/{0}/2010", i.ToString())).ToString("MMMM")
Dt.Rows.Add(Dr)
Next
Return Dt
End Function
End Class
|
 |
 |
 |
 |
Date :
2010-06-04 15:01:10 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2010-06-04 15:43:05 |
By :
เนย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีวิธีลบแบบเลือก row ใน gridview แล้วใช้ปุ่ม delete นอก gridview มั้ยค่ะ
หรือ edit ข้อมูลใน gridview โดยเลือก row แล้วกดปุ่ม edit นอก gridview
|
 |
 |
 |
 |
Date :
2011-01-25 03:30:05 |
By :
หนึ่ง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|