problem with InsertItemTemplate

Discussion in 'ASP .Net Datagrid Control' started by Cas, Oct 28, 2006.

  1. Cas

    Cas Guest

    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
     
    Cas, Oct 28, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pjbates
    Replies:
    1
    Views:
    4,550
    Dan Vogt
    May 2, 2006
  2. Swetha
    Replies:
    0
    Views:
    3,726
    Swetha
    Nov 14, 2005
  3. jobs at webdos
    Replies:
    0
    Views:
    708
    jobs at webdos
    Oct 9, 2006
  4. Cas
    Replies:
    0
    Views:
    473
  5. Cas

    problem with InsertItemTemplate

    Cas, Oct 28, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    144
Loading...

Share This Page