G
Georg Scholz
Dear all,
I'm writing an ASP.NET application, which allows flexible editing of
tables stored in an oracle database. Therefore, it is necessary to
create all the bound columns at RUNTIME.
So far, I'm already able to create bound columns and also to create an
"Edit" Button column.
The problem is, whenever you are clicking on "Edit", then the DataGrid
switches to the original layout which is defined in the Visual Studio
designer! In other words, all columns get lost, and I get a complete
other column design.
Somehow the DataGrid seems to distinguish between an "Select Mode" and
an "Edit Mode". However, I wasn't able to get out how this Edit Mode is
defined!?
I'm posting some code below.
Any help is highly appreciated!
Thanks in advance
Georg Scholz
Imports System.Data.OleDb
Imports System.Diagnostics
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
[...]
#End Region
' Everything is starting here
' After the Users clicks a button,
' dynamically create Bound columns, then load data.
'
' This is a hard-coded test case here.
' Normally, you would create the columns by iterating through
' the dataset's columns.
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSQL.Click
Me.msgrid.Columns.Clear()
Dim colBound As New System.Web.UI.WebControls.BoundColumn
colBound.DataField = "CCKEY"
colBound.HeaderText = "CCKEY"
colBound.Initialize()
Me.msgrid.Columns.Add(colBound)
colBound = New System.Web.UI.WebControls.BoundColumn
colBound.DataField = "CCDESC"
colBound.HeaderText = "CCDESC"
Me.msgrid.Columns.Add(colBound)
Dim colEdit As New System.Web.UI.WebControls.EditCommandColumn
colEdit.ButtonType = ButtonColumnType.PushButton
colEdit.EditText = "Edit"
colEdit.CancelText = "Cancel"
Me.msgrid.Columns.Add(colEdit)
UpdateView()
End Sub
Private Sub UpdateView()
Dim strSQL As String = "SELECT CCKEY, CCDESC FROM T_COSTCENTERS"
Dim conn As OleDbConnection = New OleDbConnection("Provider=...)
Dim da As New OleDbDataAdapter(strSQL, conn)
Dim ds As New DataSet
da.Fill(ds, "MyTable")
Me.msgrid.DataSource = ds.Tables("MyTable")
Me.msgrid.DataBind()
End Sub
Private Sub msgrid_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
msgrid.EditCommand
msgrid.EditItemIndex = e.Item.ItemIndex
UpdateView()
End Sub
End Class
I'm writing an ASP.NET application, which allows flexible editing of
tables stored in an oracle database. Therefore, it is necessary to
create all the bound columns at RUNTIME.
So far, I'm already able to create bound columns and also to create an
"Edit" Button column.
The problem is, whenever you are clicking on "Edit", then the DataGrid
switches to the original layout which is defined in the Visual Studio
designer! In other words, all columns get lost, and I get a complete
other column design.
Somehow the DataGrid seems to distinguish between an "Select Mode" and
an "Edit Mode". However, I wasn't able to get out how this Edit Mode is
defined!?
I'm posting some code below.
Any help is highly appreciated!
Thanks in advance
Georg Scholz
Imports System.Data.OleDb
Imports System.Diagnostics
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
[...]
#End Region
' Everything is starting here
' After the Users clicks a button,
' dynamically create Bound columns, then load data.
'
' This is a hard-coded test case here.
' Normally, you would create the columns by iterating through
' the dataset's columns.
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSQL.Click
Me.msgrid.Columns.Clear()
Dim colBound As New System.Web.UI.WebControls.BoundColumn
colBound.DataField = "CCKEY"
colBound.HeaderText = "CCKEY"
colBound.Initialize()
Me.msgrid.Columns.Add(colBound)
colBound = New System.Web.UI.WebControls.BoundColumn
colBound.DataField = "CCDESC"
colBound.HeaderText = "CCDESC"
Me.msgrid.Columns.Add(colBound)
Dim colEdit As New System.Web.UI.WebControls.EditCommandColumn
colEdit.ButtonType = ButtonColumnType.PushButton
colEdit.EditText = "Edit"
colEdit.CancelText = "Cancel"
Me.msgrid.Columns.Add(colEdit)
UpdateView()
End Sub
Private Sub UpdateView()
Dim strSQL As String = "SELECT CCKEY, CCDESC FROM T_COSTCENTERS"
Dim conn As OleDbConnection = New OleDbConnection("Provider=...)
Dim da As New OleDbDataAdapter(strSQL, conn)
Dim ds As New DataSet
da.Fill(ds, "MyTable")
Me.msgrid.DataSource = ds.Tables("MyTable")
Me.msgrid.DataBind()
End Sub
Private Sub msgrid_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
msgrid.EditCommand
msgrid.EditItemIndex = e.Item.ItemIndex
UpdateView()
End Sub
End Class