473,325 Members | 2,308 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,325 software developers and data experts.

problem with InsertItemTemplate

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.DetailsViewInsertEventAr gs) 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
Oct 28 '06 #1
0 1456

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

Similar topics

1
by: pjbates | last post by:
Hi, I've been using the GridView and DetailsView controls for a while, and I'm beginning to get annoyed by the redundancy of EditItemTemplate and InsertItemTemplate in many cases. In the...
0
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money...
0
by: Sam | last post by:
Folks.. I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data...
1
by: Microsoft News Group | last post by:
I am trying to validate two textboxes as their values are the same, or both are null do not insert the data. I do not just want one to try to be null, I want both of them, so the requirevalidator...
2
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import...
4
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString;...
0
by: Cas | last post by:
Hi, I want to create a InsertItemTemplate in a detailsview (only insertmode)programmatically. I first defined a Template, then i tried to create within that templatefield a InsertItemTemplate...
1
by: Trev | last post by:
Hi, I'm hoping that someone in this group can shed some light on an issue I'm having with a Formview. I have a Web User Control (.ascx) with a Formview. The Formview contains 2 Multiviews,...
0
by: =?Utf-8?B?U2F0aGVlc2g=?= | last post by:
Hi all, When the below code executed it is not binding the Dropdownlist in insertitemtemplate. But the same is binding the Dropdownlist in EditItemTemplate. Also, when i use LINQDataSource in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.