473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

only for expert: what's wrong with this code?

Cas
Hi,

I want to use a detailsview only for inserting data into a database (for a
survey). In order to check the inputted data, i need Templatefield.
So I defined a detailsview and a SqlDataSource in the aspx file.
The creation of the templatefields are done programmatically, because the
number of fields vary (fieldnames are fetched from the same sqldatasource).

Now, my problem: no error, the detailsview renders the right fieldheaders
and the texboxs, but when clicking on the Inset button, i can see there is a
postback, but the ItemInserting procedure is not started (so no inserting)
and the texboxs are gone!!

Thanks for help
Cas

The code:
1) the class:
-----------
Public Class DetailsViewTemplate
Inherits System.Web.UI.Page
Implements ITemplate
Dim templatetype As ListItemType
Dim columnname As String

Public Sub New(ByVal type As ListItemType, ByVal vg As String)
templatetype = type
columnname = vg
End Sub

Private Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
Case ListItemType.EditItem
Dim tb = New TextBox()
tb.Text = ""
container.Controls.Add(tb)
End Select
End Sub
End Class

2) code-behind
---------------
Imports System.Data.OleDb
Partial Class excel
Inherits System.Web.UI.Page
Friend nfield As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim sql As String
Dim oConnection As OleDbConnection
'Dim sConnectionString As String
oConnection = New OleDbConnection()

Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

SqlDataSource1.DataBind()
oConnection.ConnectionString = SqlDataSource1.ConnectionString
oConnection.Open()
Dim i As Integer
sql = "select count(*) from fld;"
comd = New OleDbCommand(sql, oConnection)
nfield = comd.ExecuteScalar
nfieldout = nfield

sql = "select * from fld;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
Dim bf(nfield) As TemplateField

If Not Page.IsPostBack Then
For i = 0 To nfield - 1
dtreader.Read()
bf(i) = New TemplateField
bf(i).ItemTemplate = New
DetailsViewTemplate(ListItemType.Item, "fld" & nfield)
bf(i).InsertItemTemplate = New
DetailsViewTemplate(ListItemType.EditItem, "fld" & nfield)
DetailsView1.Fields.Add(bf(i))
Next
dtreader.Close()

Dim cf As CommandField
cf = New CommandField
cf.ShowInsertButton = True
DetailsView1.Fields.Add(cf)
End If
oConnection.Close()
End Sub

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventAr gs) Handles
DetailsView1.ItemInserting
Dim fd, vl, wd,inscomm, a, vlfin As String
Dim i, j, tel As Integer
For i = 1 To nfield
fd= fd & "field" & i & ","
vl = e.Values("fld" & i)
wd = wd & "'" & vlfin & "',"
vlfin = ""
Next
vragen = vragen & ") values ('" & lol & "',"
inscomm = "insert into data (login," & fd &wd
SqlDataSource1.InsertCommand = inscomm
SqlDataSource1.ProviderName = "System.Data.OleDb"
End Sub
End Class


Oct 25 '06 #1
3 1471
Re: only for expert:

Boy, I hope an expert shows up soon.

Bob Lehmann

"Cas" <ca*@qscq.opwrote in message
news:u5****************@TK2MSFTNGP04.phx.gbl...
Hi,

I want to use a detailsview only for inserting data into a database (for a
survey). In order to check the inputted data, i need Templatefield.
So I defined a detailsview and a SqlDataSource in the aspx file.
The creation of the templatefields are done programmatically, because the
number of fields vary (fieldnames are fetched from the same
sqldatasource).
>
Now, my problem: no error, the detailsview renders the right fieldheaders
and the texboxs, but when clicking on the Inset button, i can see there is
a
postback, but the ItemInserting procedure is not started (so no inserting)
and the texboxs are gone!!

Thanks for help
Cas

The code:
1) the class:
-----------
Public Class DetailsViewTemplate
Inherits System.Web.UI.Page
Implements ITemplate
Dim templatetype As ListItemType
Dim columnname As String

Public Sub New(ByVal type As ListItemType, ByVal vg As String)
templatetype = type
columnname = vg
End Sub

Private Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
Case ListItemType.EditItem
Dim tb = New TextBox()
tb.Text = ""
container.Controls.Add(tb)
End Select
End Sub
End Class

2) code-behind
---------------
Imports System.Data.OleDb
Partial Class excel
Inherits System.Web.UI.Page
Friend nfield As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim sql As String
Dim oConnection As OleDbConnection
'Dim sConnectionString As String
oConnection = New OleDbConnection()

Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

SqlDataSource1.DataBind()
oConnection.ConnectionString = SqlDataSource1.ConnectionString
oConnection.Open()
Dim i As Integer
sql = "select count(*) from fld;"
comd = New OleDbCommand(sql, oConnection)
nfield = comd.ExecuteScalar
nfieldout = nfield

sql = "select * from fld;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
Dim bf(nfield) As TemplateField

If Not Page.IsPostBack Then
For i = 0 To nfield - 1
dtreader.Read()
bf(i) = New TemplateField
bf(i).ItemTemplate = New
DetailsViewTemplate(ListItemType.Item, "fld" & nfield)
bf(i).InsertItemTemplate = New
DetailsViewTemplate(ListItemType.EditItem, "fld" & nfield)
DetailsView1.Fields.Add(bf(i))
Next
dtreader.Close()

Dim cf As CommandField
cf = New CommandField
cf.ShowInsertButton = True
DetailsView1.Fields.Add(cf)
End If
oConnection.Close()
End Sub

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventAr gs) Handles
DetailsView1.ItemInserting
Dim fd, vl, wd,inscomm, a, vlfin As String
Dim i, j, tel As Integer
For i = 1 To nfield
fd= fd & "field" & i & ","
vl = e.Values("fld" & i)
wd = wd & "'" & vlfin & "',"
vlfin = ""
Next
vragen = vragen & ") values ('" & lol & "',"
inscomm = "insert into data (login," & fd &wd
SqlDataSource1.InsertCommand = inscomm
SqlDataSource1.ProviderName = "System.Data.OleDb"
End Sub
End Class


Oct 25 '06 #2
<sarcasticmode >
Don`t know if my expertise is considered "good enough" so i dear not to
answer this question :-)
</sarcasticmode>

regards
Michel Posseth [MCP]

"Bob Lehmann" <no****@dontbotherme.zzzschreef in bericht
news:eL****************@TK2MSFTNGP02.phx.gbl...
Re: only for expert:

Boy, I hope an expert shows up soon.

Bob Lehmann

"Cas" <ca*@qscq.opwrote in message
news:u5****************@TK2MSFTNGP04.phx.gbl...
>Hi,

I want to use a detailsview only for inserting data into a database (for
a
survey). In order to check the inputted data, i need Templatefield.
So I defined a detailsview and a SqlDataSource in the aspx file.
The creation of the templatefields are done programmatically, because the
number of fields vary (fieldnames are fetched from the same
sqldatasource).
>>
Now, my problem: no error, the detailsview renders the right fieldheaders
and the texboxs, but when clicking on the Inset button, i can see there
is
a
>postback, but the ItemInserting procedure is not started (so no
inserting)
and the texboxs are gone!!

Thanks for help
Cas

The code:
1) the class:
-----------
Public Class DetailsViewTemplate
Inherits System.Web.UI.Page
Implements ITemplate
Dim templatetype As ListItemType
Dim columnname As String

Public Sub New(ByVal type As ListItemType, ByVal vg As String)
templatetype = type
columnname = vg
End Sub

Private Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
Case ListItemType.EditItem
Dim tb = New TextBox()
tb.Text = ""
container.Controls.Add(tb)
End Select
End Sub
End Class

2) code-behind
---------------
Imports System.Data.OleDb
Partial Class excel
Inherits System.Web.UI.Page
Friend nfield As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim sql As String
Dim oConnection As OleDbConnection
'Dim sConnectionString As String
oConnection = New OleDbConnection()

Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

SqlDataSource1.DataBind()
oConnection.ConnectionString = SqlDataSource1.ConnectionString
oConnection.Open()
Dim i As Integer
sql = "select count(*) from fld;"
comd = New OleDbCommand(sql, oConnection)
nfield = comd.ExecuteScalar
nfieldout = nfield

sql = "select * from fld;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
Dim bf(nfield) As TemplateField

If Not Page.IsPostBack Then
For i = 0 To nfield - 1
dtreader.Read()
bf(i) = New TemplateField
bf(i).ItemTemplate = New
DetailsViewTemplate(ListItemType.Item, "fld" & nfield)
bf(i).InsertItemTemplate = New
DetailsViewTemplate(ListItemType.EditItem, "fld" & nfield)
DetailsView1.Fields.Add(bf(i))
Next
dtreader.Close()

Dim cf As CommandField
cf = New CommandField
cf.ShowInsertButton = True
DetailsView1.Fields.Add(cf)
End If
oConnection.Close()
End Sub

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventAr gs) Handles
DetailsView1.ItemInserting
Dim fd, vl, wd,inscomm, a, vlfin As String
Dim i, j, tel As Integer
For i = 1 To nfield
fd= fd & "field" & i & ","
vl = e.Values("fld" & i)
wd = wd & "'" & vlfin & "',"
vlfin = ""
Next
vragen = vragen & ") values ('" & lol & "',"
inscomm = "insert into data (login," & fd &wd
SqlDataSource1.InsertCommand = inscomm
SqlDataSource1.ProviderName = "System.Data.OleDb"
End Sub
End Class



Oct 25 '06 #3
Cas
I'm sure it is. So go ahead ...
Thanks in advance.

"Michel Posseth [MCP]" <MS**@posseth.comschreef in bericht
news:OR******************@TK2MSFTNGP03.phx.gbl...
<sarcasticmode >
Don`t know if my expertise is considered "good enough" so i dear not to
answer this question :-)
</sarcasticmode>

regards
Michel Posseth [MCP]

"Bob Lehmann" <no****@dontbotherme.zzzschreef in bericht
news:eL****************@TK2MSFTNGP02.phx.gbl...
>Re: only for expert:

Boy, I hope an expert shows up soon.

Bob Lehmann

"Cas" <ca*@qscq.opwrote in message
news:u5****************@TK2MSFTNGP04.phx.gbl...
>>Hi,

I want to use a detailsview only for inserting data into a database (for
a
survey). In order to check the inputted data, i need Templatefield.
So I defined a detailsview and a SqlDataSource in the aspx file.
The creation of the templatefields are done programmatically, because
the
number of fields vary (fieldnames are fetched from the same
sqldatasource).
>>>
Now, my problem: no error, the detailsview renders the right
fieldheaders
and the texboxs, but when clicking on the Inset button, i can see there
is
a
>>postback, but the ItemInserting procedure is not started (so no
inserting)
and the texboxs are gone!!

Thanks for help
Cas

The code:
1) the class:
-----------
Public Class DetailsViewTemplate
Inherits System.Web.UI.Page
Implements ITemplate
Dim templatetype As ListItemType
Dim columnname As String

Public Sub New(ByVal type As ListItemType, ByVal vg As String)
templatetype = type
columnname = vg
End Sub

Private Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
Case ListItemType.EditItem
Dim tb = New TextBox()
tb.Text = ""
container.Controls.Add(tb)
End Select
End Sub
End Class

2) code-behind
---------------
Imports System.Data.OleDb
Partial Class excel
Inherits System.Web.UI.Page
Friend nfield As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim sql As String
Dim oConnection As OleDbConnection
'Dim sConnectionString As String
oConnection = New OleDbConnection()

Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

SqlDataSource1.DataBind()
oConnection.ConnectionString = SqlDataSource1.ConnectionString
oConnection.Open()
Dim i As Integer
sql = "select count(*) from fld;"
comd = New OleDbCommand(sql, oConnection)
nfield = comd.ExecuteScalar
nfieldout = nfield

sql = "select * from fld;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
Dim bf(nfield) As TemplateField

If Not Page.IsPostBack Then
For i = 0 To nfield - 1
dtreader.Read()
bf(i) = New TemplateField
bf(i).ItemTemplate = New
DetailsViewTemplate(ListItemType.Item, "fld" & nfield)
bf(i).InsertItemTemplate = New
DetailsViewTemplate(ListItemType.EditItem, "fld" & nfield)
DetailsView1.Fields.Add(bf(i))
Next
dtreader.Close()

Dim cf As CommandField
cf = New CommandField
cf.ShowInsertButton = True
DetailsView1.Fields.Add(cf)
End If
oConnection.Close()
End Sub

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventAr gs) Handles
DetailsView1.ItemInserting
Dim fd, vl, wd,inscomm, a, vlfin As String
Dim i, j, tel As Integer
For i = 1 To nfield
fd= fd & "field" & i & ","
vl = e.Values("fld" & i)
wd = wd & "'" & vlfin & "',"
vlfin = ""
Next
vragen = vragen & ") values ('" & lol & "',"
inscomm = "insert into data (login," & fd &wd
SqlDataSource1.InsertCommand = inscomm
SqlDataSource1.ProviderName = "System.Data.OleDb"
End Sub
End Class




Oct 26 '06 #4

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

Similar topics

3
by: Silvio Lopes de Oliveira | last post by:
Hello, I have a C++ / MFC app which uses CDatabase and CRecordset to connect to a ODBC data source for a SQL Server 7 database. The application worked properly with a MySQL database, but after...
21
by: fleemo17 | last post by:
I'm diving into the world of CSS and am blown away by the power of it. I'm redesigning a website, trying to eliminate the tables in the layout in favor of CSS. However I've come across a stumbling...
7
by: Brian Genisio | last post by:
Hello all, I am developing a class where speed is important, and memory size is also important. I need to give the user of the class read-only access to one of the private members (size as an...
15
by: Don Vaillancourt | last post by:
I do a lot of hiring for my company and a lot of the people I interview say that they are experts at SQL queries, but when I give them something simple just beyond the typical SELECT type of...
1
by: Migrators | last post by:
I want to become an expert in C programming. Where can I find free electronic versions (.pdf or .doc) of C materials so that I can download it and study. Please specify the links.
1
by: Kate Luu | last post by:
I have down load some source codes from the internet and it wasn't worked right, but I'm really know what's wrong about it. May some expert help me please...I'm deeply appreciated for your help....
6
by: Mike Miller | last post by:
Question: How do you develop a web service that uses unknown types? The ideas is that my web service performs a generic function. I want anyone to be able to consume it, but I can't know what...
9
by: Daniel | last post by:
Looking to see if anyone can offer some suggestions on some good VB.net books? looking for beginner to intermidiate and to expert.. Any suggestions? -- ASP, SQL2005, DW8 VBScript
37
by: Mason C | last post by:
I have a small, validated page that uses "bgcolor" in <body... and several <td... 's The colors show ok in Opera but not in MSIE or Firefox. http://frontal-lobe.info/link2pdf.html I've been...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.