M
Mark
I have been working for quite some time on this issue which in theory
should be quite simple. The problem is that the Cancel and Save
events are not fired when their respective buttons are clicked.
I have read several posts which say to put your column generating
section in the Page_Init section and it will solve the
problem....however, it hasn't solved mine.
Can somebody please take a look at this and provide any insight if
possible?
Thanks,
Mark
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class DynaGrid
Inherits System.Web.UI.Page
Protected WithEvents plcData As
System.Web.UI.WebControls.PlaceHolder
Protected WithEvents dgData As New
System.Web.UI.WebControls.DataGrid()
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<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
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
BindData()
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub
Sub BindData()
Dim dbConn As New OleDbConnection()
dbConn.ConnectionString =
"provider=sqloledb;Server=SERVERNAME;Database=User;UID=USERID;PWD=PASSWORD"
Dim oAdapter As New OleDbDataAdapter("SELECT * FROM T_Group ",
dbConn)
Dim dsData As New DataSet()
oAdapter.Fill(dsData)
dgData.AllowPaging = False
dgData.AllowSorting = False
dgData.AutoGenerateColumns = False
'dgData.EnableViewState = False
Dim x As Integer
For x = 0 To dsData.Tables(0).Columns.Count - 1
Dim bcCol As New BoundColumn()
bcCol.HeaderText = dsData.Tables(0).Columns(x).ColumnName
bcCol.DataField = dsData.Tables(0).Columns(x).Caption
dgData.Columns.Add(bcCol)
bcCol = Nothing
Next
Dim bcEdit As New EditCommandColumn()
bcEdit.ButtonType = ButtonColumnType.PushButton
bcEdit.EditText = "Edit"
bcEdit.CancelText = "Cancel"
bcEdit.UpdateText = "Save"
dgData.Columns.Add(bcEdit)
bcEdit = Nothing
dgData.DataSource = dsData.Tables(0)
dgData.DataBind()
AddHandler dgData.CancelCommand, AddressOf dgData_cmdCancel
AddHandler dgData.EditCommand, AddressOf dgData_cmdEdit
plcData.Controls.Add(dgData)
End Sub
Sub dgData_cmdSave(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
dgData.EditItemIndex = -1
Response.Write(e.CommandName)
dgData.DataBind()
End Sub
Sub dgData_cmdCancel(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
dgData.EditItemIndex = -1
Response.Write(e.CommandName)
dgData.DataBind()
End Sub
Sub dgData_cmdEdit(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
dgData.EditItemIndex = CInt(e.Item.ItemIndex)
Response.Write(e.CommandName)
dgData.DataBind()
End Sub
End Class
should be quite simple. The problem is that the Cancel and Save
events are not fired when their respective buttons are clicked.
I have read several posts which say to put your column generating
section in the Page_Init section and it will solve the
problem....however, it hasn't solved mine.
Can somebody please take a look at this and provide any insight if
possible?
Thanks,
Mark
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class DynaGrid
Inherits System.Web.UI.Page
Protected WithEvents plcData As
System.Web.UI.WebControls.PlaceHolder
Protected WithEvents dgData As New
System.Web.UI.WebControls.DataGrid()
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<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
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
BindData()
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub
Sub BindData()
Dim dbConn As New OleDbConnection()
dbConn.ConnectionString =
"provider=sqloledb;Server=SERVERNAME;Database=User;UID=USERID;PWD=PASSWORD"
Dim oAdapter As New OleDbDataAdapter("SELECT * FROM T_Group ",
dbConn)
Dim dsData As New DataSet()
oAdapter.Fill(dsData)
dgData.AllowPaging = False
dgData.AllowSorting = False
dgData.AutoGenerateColumns = False
'dgData.EnableViewState = False
Dim x As Integer
For x = 0 To dsData.Tables(0).Columns.Count - 1
Dim bcCol As New BoundColumn()
bcCol.HeaderText = dsData.Tables(0).Columns(x).ColumnName
bcCol.DataField = dsData.Tables(0).Columns(x).Caption
dgData.Columns.Add(bcCol)
bcCol = Nothing
Next
Dim bcEdit As New EditCommandColumn()
bcEdit.ButtonType = ButtonColumnType.PushButton
bcEdit.EditText = "Edit"
bcEdit.CancelText = "Cancel"
bcEdit.UpdateText = "Save"
dgData.Columns.Add(bcEdit)
bcEdit = Nothing
dgData.DataSource = dsData.Tables(0)
dgData.DataBind()
AddHandler dgData.CancelCommand, AddressOf dgData_cmdCancel
AddHandler dgData.EditCommand, AddressOf dgData_cmdEdit
plcData.Controls.Add(dgData)
End Sub
Sub dgData_cmdSave(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
dgData.EditItemIndex = -1
Response.Write(e.CommandName)
dgData.DataBind()
End Sub
Sub dgData_cmdCancel(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
dgData.EditItemIndex = -1
Response.Write(e.CommandName)
dgData.DataBind()
End Sub
Sub dgData_cmdEdit(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
dgData.EditItemIndex = CInt(e.Item.ItemIndex)
Response.Write(e.CommandName)
dgData.DataBind()
End Sub
End Class