Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > only for expert: what's wrong with this code?

Reply
Thread Tools

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

 
 
Cas
Guest
Posts: n/a
 
      10-25-2006
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




 
Reply With Quote
 
 
 
 
Bob Lehmann
Guest
Posts: n/a
 
      10-25-2006
Re: only for expert:

Boy, I hope an expert shows up soon.

Bob Lehmann

"Cas" <(E-Mail Removed)> wrote in message
news:u5BHMnG%(E-Mail Removed)...
> 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
>
>
>
>



 
Reply With Quote
 
 
 
 
Michel Posseth [MCP]
Guest
Posts: n/a
 
      10-25-2006
<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" <(E-Mail Removed)> schreef in bericht
news:eL$M3kI%(E-Mail Removed)...
> Re: only for expert:
>
> Boy, I hope an expert shows up soon.
>
> Bob Lehmann
>
> "Cas" <(E-Mail Removed)> wrote in message
> news:u5BHMnG%(E-Mail Removed)...
>> 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
>>
>>
>>
>>

>
>



 
Reply With Quote
 
Cas
Guest
Posts: n/a
 
      10-26-2006
I'm sure it is. So go ahead ...
Thanks in advance.

"Michel Posseth [MCP]" <(E-Mail Removed)> schreef in bericht
news:OR9mV%23I%(E-Mail Removed)...
> <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" <(E-Mail Removed)> schreef in bericht
> news:eL$M3kI%(E-Mail Removed)...
>> Re: only for expert:
>>
>> Boy, I hope an expert shows up soon.
>>
>> Bob Lehmann
>>
>> "Cas" <(E-Mail Removed)> wrote in message
>> news:u5BHMnG%(E-Mail Removed)...
>>> 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
>>>
>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python-parser running Beautiful Soup only spits out one line of 10.What i have gotten wrong here? Martin Kaspar Python 1 12-25-2010 06:36 PM
only for expert: what's wrong with this code? Cas ASP .Net Web Controls 7 10-27-2006 02:31 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
Is JAVAscript the only thing that could wrong under a html page? Norberto Rivera Javascript 5 08-20-2004 01:17 PM
newbie question-----where is wrong.(only 19 lines code) Facco Eloelo Perl Misc 3 08-13-2004 08:50 PM



Advertisments