473,546 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Datagrid does not fire events.

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....howe ver, 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.Ole Db

Public Class DynaGrid

Inherits System.Web.UI.P age
Protected WithEvents plcData As
System.Web.UI.W ebControls.Plac eHolder
Protected WithEvents dgData As New
System.Web.UI.W ebControls.Data Grid()

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
BindData()
InitializeCompo nent()
End Sub

#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)

End Sub
Sub BindData()
Dim dbConn As New OleDbConnection ()
dbConn.Connecti onString =
"provider=sqlol edb;Server=SERV ERNAME;Database =User;UID=USERI D;PWD=PASSWORD"
Dim oAdapter As New OleDbDataAdapte r("SELECT * FROM T_Group ",
dbConn)
Dim dsData As New DataSet()
oAdapter.Fill(d sData)

dgData.AllowPag ing = False
dgData.AllowSor ting = False
dgData.AutoGene rateColumns = False
'dgData.EnableV iewState = False

Dim x As Integer
For x = 0 To dsData.Tables(0 ).Columns.Count - 1
Dim bcCol As New BoundColumn()
bcCol.HeaderTex t = dsData.Tables(0 ).Columns(x).Co lumnName
bcCol.DataField = dsData.Tables(0 ).Columns(x).Ca ption
dgData.Columns. Add(bcCol)
bcCol = Nothing
Next

Dim bcEdit As New EditCommandColu mn()
bcEdit.ButtonTy pe = ButtonColumnTyp e.PushButton
bcEdit.EditText = "Edit"
bcEdit.CancelTe xt = "Cancel"
bcEdit.UpdateTe xt = "Save"
dgData.Columns. Add(bcEdit)
bcEdit = Nothing

dgData.DataSour ce = dsData.Tables(0 )
dgData.DataBind ()

AddHandler dgData.CancelCo mmand, AddressOf dgData_cmdCance l
AddHandler dgData.EditComm and, AddressOf dgData_cmdEdit

plcData.Control s.Add(dgData)
End Sub
Sub dgData_cmdSave( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdCance l(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdEdit( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = CInt(e.Item.Ite mIndex)
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
End Class
Nov 17 '05 #1
6 4471
Mark,

Make sure that viewstate is on and that the grid is recreated every page
load.

If these two things are done it should be working.

If you'd like me to take a look at the code post it and I'll see if I can
get it to work.

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:39******** *************** ***@posting.goo gle.com...
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....howe ver, 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.Ole Db

Public Class DynaGrid

Inherits System.Web.UI.P age
Protected WithEvents plcData As
System.Web.UI.W ebControls.Plac eHolder
Protected WithEvents dgData As New
System.Web.UI.W ebControls.Data Grid()

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
BindData()
InitializeCompo nent()
End Sub

#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)

End Sub
Sub BindData()
Dim dbConn As New OleDbConnection ()
dbConn.Connecti onString =
"provider=sqlol edb;Server=SERV ERNAME;Database =User;UID=USERI D;PWD=PASSWORD" Dim oAdapter As New OleDbDataAdapte r("SELECT * FROM T_Group ",
dbConn)
Dim dsData As New DataSet()
oAdapter.Fill(d sData)

dgData.AllowPag ing = False
dgData.AllowSor ting = False
dgData.AutoGene rateColumns = False
'dgData.EnableV iewState = False

Dim x As Integer
For x = 0 To dsData.Tables(0 ).Columns.Count - 1
Dim bcCol As New BoundColumn()
bcCol.HeaderTex t = dsData.Tables(0 ).Columns(x).Co lumnName
bcCol.DataField = dsData.Tables(0 ).Columns(x).Ca ption
dgData.Columns. Add(bcCol)
bcCol = Nothing
Next

Dim bcEdit As New EditCommandColu mn()
bcEdit.ButtonTy pe = ButtonColumnTyp e.PushButton
bcEdit.EditText = "Edit"
bcEdit.CancelTe xt = "Cancel"
bcEdit.UpdateTe xt = "Save"
dgData.Columns. Add(bcEdit)
bcEdit = Nothing

dgData.DataSour ce = dsData.Tables(0 )
dgData.DataBind ()

AddHandler dgData.CancelCo mmand, AddressOf dgData_cmdCance l
AddHandler dgData.EditComm and, AddressOf dgData_cmdEdit

plcData.Control s.Add(dgData)
End Sub
Sub dgData_cmdSave( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdCance l(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdEdit( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = CInt(e.Item.Ite mIndex)
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
End Class

Nov 17 '05 #2
I did post the code.
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Mark,

Make sure that viewstate is on and that the grid is recreated every page
load.

If these two things are done it should be working.

If you'd like me to take a look at the code post it and I'll see if I can
get it to work.

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:39******** *************** ***@posting.goo gle.com...
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....howe ver, 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.Ole Db

Public Class DynaGrid

Inherits System.Web.UI.P age
Protected WithEvents plcData As
System.Web.UI.W ebControls.Plac eHolder
Protected WithEvents dgData As New
System.Web.UI.W ebControls.Data Grid()

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
BindData()
InitializeCompo nent()
End Sub

#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)

End Sub
Sub BindData()
Dim dbConn As New OleDbConnection ()
dbConn.Connecti onString =

"provider=sqlol edb;Server=SERV ERNAME;Database =User;UID=USERI D;PWD=PASSWORD"
Dim oAdapter As New OleDbDataAdapte r("SELECT * FROM T_Group ",
dbConn)
Dim dsData As New DataSet()
oAdapter.Fill(d sData)

dgData.AllowPag ing = False
dgData.AllowSor ting = False
dgData.AutoGene rateColumns = False
'dgData.EnableV iewState = False

Dim x As Integer
For x = 0 To dsData.Tables(0 ).Columns.Count - 1
Dim bcCol As New BoundColumn()
bcCol.HeaderTex t = dsData.Tables(0 ).Columns(x).Co lumnName
bcCol.DataField = dsData.Tables(0 ).Columns(x).Ca ption
dgData.Columns. Add(bcCol)
bcCol = Nothing
Next

Dim bcEdit As New EditCommandColu mn()
bcEdit.ButtonTy pe = ButtonColumnTyp e.PushButton
bcEdit.EditText = "Edit"
bcEdit.CancelTe xt = "Cancel"
bcEdit.UpdateTe xt = "Save"
dgData.Columns. Add(bcEdit)
bcEdit = Nothing

dgData.DataSour ce = dsData.Tables(0 )
dgData.DataBind ()

AddHandler dgData.CancelCo mmand, AddressOf dgData_cmdCance l
AddHandler dgData.EditComm and, AddressOf dgData_cmdEdit

plcData.Control s.Add(dgData)
End Sub
Sub dgData_cmdSave( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdCance l(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdEdit( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = CInt(e.Item.Ite mIndex)
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
End Class


Nov 17 '05 #3
Mark,

Sorry I just wasn't specific. I'll chalk up my lack of presenting a logical
request to the amount of sleep I had at the time. :)

Could you please also post the designer's code. Then I can recreate the
entire page and take a look.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:ul******** ******@TK2MSFTN GP11.phx.gbl...
I did post the code.
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Mark,

Make sure that viewstate is on and that the grid is recreated every page
load.

If these two things are done it should be working.

If you'd like me to take a look at the code post it and I'll see if I can
get it to work.

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:39******** *************** ***@posting.goo gle.com...
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....howe ver, 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.Ole Db

Public Class DynaGrid

Inherits System.Web.UI.P age
Protected WithEvents plcData As
System.Web.UI.W ebControls.Plac eHolder
Protected WithEvents dgData As New
System.Web.UI.W ebControls.Data Grid()

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
BindData()
InitializeCompo nent()
End Sub

#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)

End Sub
Sub BindData()
Dim dbConn As New OleDbConnection ()
dbConn.Connecti onString =

"provider=sqlol edb;Server=SERV ERNAME;Database =User;UID=USERI D;PWD=PASSWORD"
Dim oAdapter As New OleDbDataAdapte r("SELECT * FROM T_Group ",
dbConn)
Dim dsData As New DataSet()
oAdapter.Fill(d sData)

dgData.AllowPag ing = False
dgData.AllowSor ting = False
dgData.AutoGene rateColumns = False
'dgData.EnableV iewState = False

Dim x As Integer
For x = 0 To dsData.Tables(0 ).Columns.Count - 1
Dim bcCol As New BoundColumn()
bcCol.HeaderTex t = dsData.Tables(0 ).Columns(x).Co lumnName
bcCol.DataField = dsData.Tables(0 ).Columns(x).Ca ption
dgData.Columns. Add(bcCol)
bcCol = Nothing
Next

Dim bcEdit As New EditCommandColu mn()
bcEdit.ButtonTy pe = ButtonColumnTyp e.PushButton
bcEdit.EditText = "Edit"
bcEdit.CancelTe xt = "Cancel"
bcEdit.UpdateTe xt = "Save"
dgData.Columns. Add(bcEdit)
bcEdit = Nothing

dgData.DataSour ce = dsData.Tables(0 )
dgData.DataBind ()

AddHandler dgData.CancelCo mmand, AddressOf dgData_cmdCance l
AddHandler dgData.EditComm and, AddressOf dgData_cmdEdit

plcData.Control s.Add(dgData)
End Sub
Sub dgData_cmdSave( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdCance l(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = -1
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
Sub dgData_cmdEdit( ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs)
dgData.EditItem Index = CInt(e.Item.Ite mIndex)
Response.Write( e.CommandName)
dgData.DataBind ()
End Sub
End Class



Nov 17 '05 #4
Justin,

I appreciate you taking a look at this.

<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="Dyn aGrid.aspx.vb"
Inherits="MMDG. DynaGrid"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DynaGrid </title>
<meta name="GENERATOR " content="Micros oft Visual Studio.NET 7.0">
<meta name="CODE_LANG UAGE" content="Visual Basic 7.0">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolde r ID="plcData" Runat="server"> </asp:PlaceHolder >
</form>
</body>
</HTML>

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:uJ******** ******@TK2MSFTN GP11.phx.gbl...
Mark,

Sorry I just wasn't specific. I'll chalk up my lack of presenting a logical request to the amount of sleep I had at the time. :)

Could you please also post the designer's code. Then I can recreate the
entire page and take a look.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:ul******** ******@TK2MSFTN GP11.phx.gbl...
I did post the code.
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Mark,

Make sure that viewstate is on and that the grid is recreated every page load.

If these two things are done it should be working.

If you'd like me to take a look at the code post it and I'll see if I can get it to work.

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:39******** *************** ***@posting.goo gle.com...
> 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....howe ver, 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.Ole Db
>
> Public Class DynaGrid
>
> Inherits System.Web.UI.P age
> Protected WithEvents plcData As
> System.Web.UI.W ebControls.Plac eHolder
> Protected WithEvents dgData As New
> System.Web.UI.W ebControls.Data Grid()
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
> InitializeCompo nent()
>
> End Sub
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArg s) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form
> Designer
> 'Do not modify it using the code editor.
> BindData()
> InitializeCompo nent()
> End Sub
>
> #End Region
>
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArg s)
>
> End Sub
>
>
> Sub BindData()
> Dim dbConn As New OleDbConnection ()
> dbConn.Connecti onString =
>

"provider=sqlol edb;Server=SERV ERNAME;Database =User;UID=USERI D;PWD=PASSWORD"
> Dim oAdapter As New OleDbDataAdapte r("SELECT * FROM T_Group ", > dbConn)
> Dim dsData As New DataSet()
> oAdapter.Fill(d sData)
>
> dgData.AllowPag ing = False
> dgData.AllowSor ting = False
> dgData.AutoGene rateColumns = False
> 'dgData.EnableV iewState = False
>
> Dim x As Integer
> For x = 0 To dsData.Tables(0 ).Columns.Count - 1
> Dim bcCol As New BoundColumn()
> bcCol.HeaderTex t = dsData.Tables(0 ).Columns(x).Co lumnName > bcCol.DataField = dsData.Tables(0 ).Columns(x).Ca ption
> dgData.Columns. Add(bcCol)
> bcCol = Nothing
> Next
>
> Dim bcEdit As New EditCommandColu mn()
> bcEdit.ButtonTy pe = ButtonColumnTyp e.PushButton
> bcEdit.EditText = "Edit"
> bcEdit.CancelTe xt = "Cancel"
> bcEdit.UpdateTe xt = "Save"
> dgData.Columns. Add(bcEdit)
> bcEdit = Nothing
>
> dgData.DataSour ce = dsData.Tables(0 )
> dgData.DataBind ()
>
> AddHandler dgData.CancelCo mmand, AddressOf dgData_cmdCance l
> AddHandler dgData.EditComm and, AddressOf dgData_cmdEdit
>
> plcData.Control s.Add(dgData)
> End Sub
>
>
> Sub dgData_cmdSave( ByVal sender As Object, ByVal e As
> System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> dgData.EditItem Index = -1
> Response.Write( e.CommandName)
> dgData.DataBind ()
> End Sub
>
>
> Sub dgData_cmdCance l(ByVal sender As Object, ByVal e As
> System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> dgData.EditItem Index = -1
> Response.Write( e.CommandName)
> dgData.DataBind ()
> End Sub
>
>
> Sub dgData_cmdEdit( ByVal sender As Object, ByVal e As
> System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> dgData.EditItem Index = CInt(e.Item.Ite mIndex)
> Response.Write( e.CommandName)
> dgData.DataBind ()
> End Sub
> End Class



Nov 17 '05 #5
Mark,

It took a little while of playing to get it to work, but as it turns out all
I did was move the Call BindData() statement which is in the Page_Init sub
so that it is below the call to: InitializeCompo nent

(I should have seen it without recreating everything!)

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeCompo nent()

Call BindData()

End Sub

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Justin,

I appreciate you taking a look at this.

<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="Dyn aGrid.aspx.vb" Inherits="MMDG. DynaGrid"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DynaGrid </title>
<meta name="GENERATOR " content="Micros oft Visual Studio.NET 7.0">
<meta name="CODE_LANG UAGE" content="Visual Basic 7.0">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolde r ID="plcData" Runat="server"> </asp:PlaceHolder >
</form>
</body>
</HTML>

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:uJ******** ******@TK2MSFTN GP11.phx.gbl...
Mark,

Sorry I just wasn't specific. I'll chalk up my lack of presenting a logical
request to the amount of sleep I had at the time. :)

Could you please also post the designer's code. Then I can recreate the
entire page and take a look.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:ul******** ******@TK2MSFTN GP11.phx.gbl...
I did post the code.
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
> Mark,
>
> Make sure that viewstate is on and that the grid is recreated every page > load.
>
> If these two things are done it should be working.
>
> If you'd like me to take a look at the code post it and I'll see if I
can
> get it to work.
>
> --
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzche
> "Mark" <ma**********@y ahoo.com> wrote in message
> news:39******** *************** ***@posting.goo gle.com...
> > 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....howe ver, 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.Ole Db
> >
> > Public Class DynaGrid
> >
> > Inherits System.Web.UI.P age
> > Protected WithEvents plcData As
> > System.Web.UI.W ebControls.Plac eHolder
> > Protected WithEvents dgData As New
> > System.Web.UI.W ebControls.Data Grid()
> >
> > #Region " Web Form Designer Generated Code "
> >
> > 'This call is required by the Web Form Designer.
> > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
> > InitializeCompo nent()
> >
> > End Sub
> >
> > Private Sub Page_Init(ByVal sender As System.Object, ByVal e
As > > System.EventArg s) Handles MyBase.Init
> > 'CODEGEN: This method call is required by the Web Form
> > Designer
> > 'Do not modify it using the code editor.
> > BindData()
> > InitializeCompo nent()
> > End Sub
> >
> > #End Region
> >
> >
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As > > System.EventArg s)
> >
> > End Sub
> >
> >
> > Sub BindData()
> > Dim dbConn As New OleDbConnection ()
> > dbConn.Connecti onString =
> >
>

"provider=sqlol edb;Server=SERV ERNAME;Database =User;UID=USERI D;PWD=PASSWORD"
> > Dim oAdapter As New OleDbDataAdapte r("SELECT * FROM T_Group ",
> > dbConn)
> > Dim dsData As New DataSet()
> > oAdapter.Fill(d sData)
> >
> > dgData.AllowPag ing = False
> > dgData.AllowSor ting = False
> > dgData.AutoGene rateColumns = False
> > 'dgData.EnableV iewState = False
> >
> > Dim x As Integer
> > For x = 0 To dsData.Tables(0 ).Columns.Count - 1
> > Dim bcCol As New BoundColumn()
> > bcCol.HeaderTex t = dsData.Tables(0 ).Columns(x).Co lumnName > > bcCol.DataField = dsData.Tables(0 ).Columns(x).Ca ption
> > dgData.Columns. Add(bcCol)
> > bcCol = Nothing
> > Next
> >
> > Dim bcEdit As New EditCommandColu mn()
> > bcEdit.ButtonTy pe = ButtonColumnTyp e.PushButton
> > bcEdit.EditText = "Edit"
> > bcEdit.CancelTe xt = "Cancel"
> > bcEdit.UpdateTe xt = "Save"
> > dgData.Columns. Add(bcEdit)
> > bcEdit = Nothing
> >
> > dgData.DataSour ce = dsData.Tables(0 )
> > dgData.DataBind ()
> >
> > AddHandler dgData.CancelCo mmand, AddressOf

dgData_cmdCance l > > AddHandler dgData.EditComm and, AddressOf dgData_cmdEdit
> >
> > plcData.Control s.Add(dgData)
> > End Sub
> >
> >
> > Sub dgData_cmdSave( ByVal sender As Object, ByVal e As
> > System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> > dgData.EditItem Index = -1
> > Response.Write( e.CommandName)
> > dgData.DataBind ()
> > End Sub
> >
> >
> > Sub dgData_cmdCance l(ByVal sender As Object, ByVal e As
> > System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> > dgData.EditItem Index = -1
> > Response.Write( e.CommandName)
> > dgData.DataBind ()
> > End Sub
> >
> >
> > Sub dgData_cmdEdit( ByVal sender As Object, ByVal e As
> > System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> > dgData.EditItem Index = CInt(e.Item.Ite mIndex)
> > Response.Write( e.CommandName)
> > dgData.DataBind ()
> > End Sub
> > End Class
>
>



Nov 17 '05 #6
Mark,

Everything seems to be working for me. I would suggest however that you look
into creating your datagrid in a user control and add the user control to
the page dynamically. That way a lot of the page rendering and post back
event handlers are created for you.

Take a look at the code I offer on my website: www.aboutfortunate.com on
placing user control's on a page dynamically. It should get you started.

Just search for: Dynamic User Controls

I hope this helps.

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:e4******** ******@TK2MSFTN GP12.phx.gbl...
Justin,

Thanks for looking at this.

How many times does the dgData_cmdEdit event get called when you request the page? Every time I request the page, this event runs twice (I don't have
Zone Alarm). If I remove the AddHandler section, then it only runs once.
It's as though the AddHandler actually forces the event to run when it's
created.

I have never been able to ge the Save or Cancel events to fire under any
circumstance.

Another issue I have found: if you click on the edit button for the first
item in the grid, it goes into edit mode. If you then click on the edit
button for the second item in the list it wil go into edit mode. Then, if
you go back to the first item and click on Edit, it will not go into edit
mode (edit mode stays on the second line).

I originally thought this was due to viewstate for the dg, but even
disabling it did not work.

Thanks,
MM
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:eC******** ******@TK2MSFTN GP10.phx.gbl...
Mark,

It took a little while of playing to get it to work, but as it turns out all
I did was move the Call BindData() statement which is in the Page_Init sub
so that it is below the call to: InitializeCompo nent

(I should have seen it without recreating everything!)

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeCompo nent()

Call BindData()

End Sub

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Mark" <ma**********@y ahoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Justin,

I appreciate you taking a look at this.

<%@ Page Language="vb" AutoEventWireup ="false"

Codebehind="Dyn aGrid.aspx.vb"
Inherits="MMDG. DynaGrid"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DynaGrid </title>
<meta name="GENERATOR " content="Micros oft Visual Studio.NET 7.0">
<meta name="CODE_LANG UAGE" content="Visual Basic 7.0">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolde r ID="plcData" Runat="server"> </asp:PlaceHolder >
</form>
</body>
</HTML>

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:uJ******** ******@TK2MSFTN GP11.phx.gbl...
> Mark,
>
> Sorry I just wasn't specific. I'll chalk up my lack of presenting a
logical
> request to the amount of sleep I had at the time. :)
>
> Could you please also post the designer's code. Then I can recreate the > entire page and take a look.
>
> Sincerely,
>
> --
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzche
> "Mark" <ma**********@y ahoo.com> wrote in message
> news:ul******** ******@TK2MSFTN GP11.phx.gbl...
> > I did post the code.
> >
> >
> > "S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
> > news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
> > > Mark,
> > >
> > > Make sure that viewstate is on and that the grid is recreated every page
> > > load.
> > >
> > > If these two things are done it should be working.
> > >
> > > If you'd like me to take a look at the code post it and I'll see if
I
> can
> > > get it to work.
> > >
> > > --
> > > S. Justin Gengo, MCP
> > > Web Developer
> > >
> > > Free code library at:
> > > www.aboutfortunate.com
> > >
> > > "Out of chaos comes order."
> > > Nietzche
> > > "Mark" <ma**********@y ahoo.com> wrote in message
> > > news:39******** *************** ***@posting.goo gle.com...
> > > > 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....howe ver, 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.Ole Db
> > > >
> > > > Public Class DynaGrid
> > > >
> > > > Inherits System.Web.UI.P age
> > > > Protected WithEvents plcData As
> > > > System.Web.UI.W ebControls.Plac eHolder
> > > > Protected WithEvents dgData As New
> > > > System.Web.UI.W ebControls.Data Grid()
> > > >
> > > > #Region " Web Form Designer Generated Code "
> > > >
> > > > 'This call is required by the Web Form Designer.
> > > > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
> > > > InitializeCompo nent()
> > > >
> > > > End Sub
> > > >
> > > > Private Sub Page_Init(ByVal sender As System.Object, ByVal
e As
> > > > System.EventArg s) Handles MyBase.Init
> > > > 'CODEGEN: This method call is required by the Web Form
> > > > Designer
> > > > 'Do not modify it using the code editor.
> > > > BindData()
> > > > InitializeCompo nent()
> > > > End Sub
> > > >
> > > > #End Region
> > > >
> > > >
> > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As
> > > > System.EventArg s)
> > > >
> > > > End Sub
> > > >
> > > >
> > > > Sub BindData()
> > > > Dim dbConn As New OleDbConnection ()
> > > > dbConn.Connecti onString =
> > > >
> > >
> >
>

"provider=sqlol edb;Server=SERV ERNAME;Database =User;UID=USERI D;PWD=PASSWORD" > > > > Dim oAdapter As New OleDbDataAdapte r("SELECT * FROM

T_Group
",
> > > > dbConn)
> > > > Dim dsData As New DataSet()
> > > > oAdapter.Fill(d sData)
> > > >
> > > > dgData.AllowPag ing = False
> > > > dgData.AllowSor ting = False
> > > > dgData.AutoGene rateColumns = False
> > > > 'dgData.EnableV iewState = False
> > > >
> > > > Dim x As Integer
> > > > For x = 0 To dsData.Tables(0 ).Columns.Count - 1
> > > > Dim bcCol As New BoundColumn()
> > > > bcCol.HeaderTex t =
dsData.Tables(0 ).Columns(x).Co lumnName
> > > > bcCol.DataField =

dsData.Tables(0 ).Columns(x).Ca ption > > > > dgData.Columns. Add(bcCol)
> > > > bcCol = Nothing
> > > > Next
> > > >
> > > > Dim bcEdit As New EditCommandColu mn()
> > > > bcEdit.ButtonTy pe = ButtonColumnTyp e.PushButton
> > > > bcEdit.EditText = "Edit"
> > > > bcEdit.CancelTe xt = "Cancel"
> > > > bcEdit.UpdateTe xt = "Save"
> > > > dgData.Columns. Add(bcEdit)
> > > > bcEdit = Nothing
> > > >
> > > > dgData.DataSour ce = dsData.Tables(0 )
> > > > dgData.DataBind ()
> > > >
> > > > AddHandler dgData.CancelCo mmand, AddressOf

dgData_cmdCance l
> > > > AddHandler dgData.EditComm and, AddressOf dgData_cmdEdit > > > >
> > > > plcData.Control s.Add(dgData)
> > > > End Sub
> > > >
> > > >
> > > > Sub dgData_cmdSave( ByVal sender As Object, ByVal e As
> > > > System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> > > > dgData.EditItem Index = -1
> > > > Response.Write( e.CommandName)
> > > > dgData.DataBind ()
> > > > End Sub
> > > >
> > > >
> > > > Sub dgData_cmdCance l(ByVal sender As Object, ByVal e As
> > > > System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> > > > dgData.EditItem Index = -1
> > > > Response.Write( e.CommandName)
> > > > dgData.DataBind ()
> > > > End Sub
> > > >
> > > >
> > > > Sub dgData_cmdEdit( ByVal sender As Object, ByVal e As
> > > > System.Web.UI.W ebControls.Data GridCommandEven tArgs)
> > > > dgData.EditItem Index = CInt(e.Item.Ite mIndex)
> > > > Response.Write( e.CommandName)
> > > > dgData.DataBind ()
> > > > End Sub
> > > > End Class
> > >
> > >
> >
> >
>
>



Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9204
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I click on a row (withs will turn blue then) and then click on it again . Now if I press any key the event will fire (except for the arrow keys). I...
4
1510
by: Jim Heavey | last post by:
Hello, I am starting to learn how to use the Datagrid and I have a couple of questions. My datagrid as a checkbox in it. It looks like the following in the datagrid... <asp:TemplateColumn HeaderText="Check In"> <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle> <ItemTemplate> <asp:CheckBox id="chkReturn" runat="server"...
1
7549
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
2
2378
by: andla | last post by:
Hi, How does events fire in a datagrid. I know about the problem if turning the viewstate off the events wil not fire properly even if I rebind the control in every postback. S then I started to think how does .Net do it if I turn the viewstat on. If you use the Request.Form then you can get all the controls tha
2
2572
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has to be scrolled down completely to see the page number links. The page number should always be visible outside the scroll bar. Basically I want to...
0
1736
by: tafpin | last post by:
I have an application with a datagrid. In the IDE I have 2 template columns. The first has an image button and the second contains a link button. According to the results that I get back I must add more columns to the datagrid. This is a sample of how I am adding these colums: templateColumn = New TemplateColumn
4
10595
by: Fueled | last post by:
Hi everyone! I've made quite a lot of research on this, and I've tried a couple of proposed solutions. Nothing has worked for me, but I feel there's not much I'm missing. So I'm turning to this group and its experts for answers. So : - I've got a main page (main.aspx) - On this page, I've got a button (btnArchive), on whose click I...
5
6682
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious missing here, but after 2 days I am ready to explode ! Please help. To create the Delete button I selected the grid in design view, clicked the...
0
1654
by: WhiteWizard | last post by:
I am trying to implement standard multi-select of rows in a datagrid. That is, allow the user to use the CTRL & SHIFT keys to select multiple rows in a datagrid. Then I'll loop through them and process the selected rows. The problem is that the KEY events don't seem to be firing on the datagrid. When I just click on a column of the datagrid,...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.