Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2006, 10:14 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with InsertItemTemplate

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


 
Old April 8th, 2008, 12:10 PM
Registered User
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello there...

did you manage to solve the problem...????

i'll appreciate your help...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding a date field in InsertItemTemplate fails jpullam ASP.NET 2.0 Basics 0 November 14th, 2006 10:50 AM
how to create an InsertItemTemplate in detailsview hertendreef Pro Visual Basic 2005 0 October 23rd, 2006 02:23 AM
how to create an InsertItemTemplate in detailsview hertendreef ASP.NET 2.0 Professional 0 October 23rd, 2006 02:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.