problem with InsertItemTemplate

C

Cas

Hi,

I made programmatically 30 InsertItemTemplates for a detailsview in insert
mode for a websurvey. On the detailsview, i can see the 30 textboxes and the
labels with "This is question x" . The backcolor is also ok. My problem is
that the values inserted into the detailsview are somewhere lost, so nothing
is inserted in the database. The sub DetailsView1_ItemInserting is
triggered, but there are no values. There are no error message.

Thanks for any help

Here my code:

aspx file:
----------
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Provider = ...></asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="SqlDataSource1" DefaultMode="Insert"></asp:DetailsView>

file in APPS_CODE:
-----------------
Imports Microsoft.VisualBasic

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

Select Case templatetype
Case ListItemType.Header
'Dim lb = New Label
'lb.Text = columnname
'container.Controls.Add(lb)

Case ListItemType.EditItem
Dim tb = New TextBox()
container.Controls.Add(tb)
End Select
End Sub
End Class

code-behind:
-------------
Partial Class test
Inherits System.Web.UI.Page
'---------------------------------------
Protected Sub DetailsView1_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.Init
.................
For i = 0 To 30
bf(i) = New TemplateField
vg = "question" & i
bf(i).InsertItemTemplate = New
DetailsViewTemplate(ListItemType.EditItem, vg)
DetailsView1.Fields.Add(bf(i))

DetailsView1.Fields(i).HeaderText = "This is question " & i
DetailsView1.Fields(i).ControlStyle.BackColor =
System.Drawing.ColorTranslator.FromHtml("#E0F0F0")
Next
oConnection.Close()
End Sub
'---------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim sql As String
If Not Page.IsPostBack Then
Dim cf As CommandField
cf = New CommandField
cf.ShowInsertButton = True
DetailsView1.Fields.Add(cf)
End If
End Sub
'----------------------------------------
Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView1.ItemInserting
Dim question, valu, vl, inscomm As String
Dim i, j, tel As Integer
For i = 1 To 30
question = question & i & ","
vl = e.Values("question" & i)
'is empty !!!
valu = valu & "'" & vl & "',"
Next

valu = Left(valu, Len(valu) - 2)
valu = valu & "')"
question = Left(question, Len(question) - 1)
question = question & ") values ('" & lol & "',"

inscomm = "insert into data (" & question & valu
SqlDataSource1.InsertCommand = inscomm
SqlDataSource1.ProviderName = "System.Data.OleDb"
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top