HighTechTalks DotNet Forums  

Problem creating TemplateFields in DetailsView dynamically

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss Problem creating TemplateFields in DetailsView dynamically in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Stefan Dirks
 
Posts: n/a

Default Problem creating TemplateFields in DetailsView dynamically - 11-26-2007 , 03:21 AM






Hello,

I want to create a TempalteField in a DetailsView dynamically. I call the
"SetDetailsTemplateFields"-Method on every Postback (Page_OnLoad).

The Problem that occurs is, that on every Postback I get a new row, but the
TemplateField is only created in the last row.

Example:

ID 10

Name Smith

Memo [ ] <- TemplateField

After Postback:

ID 10

Name Smith

Memo

Memo [ ] <- TemplateField

When I try to update the DetailsView I get an ArgumentOutOfRangeException.

How can I make sure, that only one row is created for every TemplateField?

Thanks and regards,

Stefan



Public Class AddTemplateToDetailsView

Implements ITemplate


Private m_ListItemType As ListItemType
Private m_Field As New DetailField



Public Sub New(ByVal _listItemType As ListItemType, ByVal _field As
DetailField)

m_ListItemType = _listItemType
m_Field = _field

End Sub


Public Sub InstantiateIn(ByVal container As System.Web.UI.Control)
Implements System.Web.UI.ITemplate.InstantiateIn

Select Case m_ListItemType

Case ListItemType.Item

Select Case m_Field.ItemType.ToLower()

Case "textbox_multi"

Dim tb As New TextBox
tb.Rows = 5
tb.TextMode = TextBoxMode.MultiLine
tb.Text = "Test"

container.Controls.Add(tb)

Case Else

End Select

Case Else


Throw New Exception("Unknown ListItemType.")

End Select

End Sub



Public Sub SetDetailsTemplateFields(ByRef _dv As
System.Web.UI.WebControls.DetailsView, ByVal _dvdId As String)

Dim oDBSqlClient As New DBSqlClient()
Dim dvFields(0) As DetailField

dvFields = oDBSqlClient.GetDetailViewFields(_dvdId)

Dim counter As Integer = 0

For Each dvField As DetailField In dvFields

If counter <> 0 Then

ReDim Preserve dvFields(counter)

End If


Select Case dvField.Type.ToLower()


Case "template"

Dim tf As TemplateField = New TemplateField()

If Not String.IsNullOrEmpty(dvField.ItemType) Then
tf.ItemTemplate = New
AddTemplateToDetailsView(ListItemType.Item, dvField)
End If
If Not String.IsNullOrEmpty(dvField.EditType) Then
tf.EditItemTemplate = New
AddTemplateToDetailsView(ListItemType.EditItem, dvField)
End If
If Not String.IsNullOrEmpty(dvField.InsertType) Then
tf.InsertItemTemplate = New
AddTemplateToDetailsView(ListItemType.SelectedItem , dvField)

End If

tf.HeaderText = dvField.HeaderText


_dv.Fields.Add(tf)


End Select

counter += 1

Next

End Sub



Reply With Quote
  #2  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default RE: Problem creating TemplateFields in DetailsView dynamically - 11-27-2007 , 03:19 AM






Hi Stefan,

This is a quick note to let you know that I am performing research on this
issue and will get back to you as soon as possible. I appreciate your
patience.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #3  
Old   
Stefan Dirks
 
Posts: n/a

Default Re: Problem creating TemplateFields in DetailsView dynamically - 11-27-2007 , 09:58 AM



Hi Walter,

thank you very much for your answer.

The problem is just solved. The fields "id" and "name" are BoundFields. I
now clear the entire DetailsView-Fields and create the bound and
templatefields on every postback. Is there another way to handle this?

I have another question concerning the databinding of the TemplateField. I
use a SqlDataSource. The BoundFields have the DataValue-Property to bind the
Update-/Insert-Parameter to the SqlDataSource. How can I bind a
TemplateField to the SqlDataSource? When I try to update a dataset I allways
get the error-message, that the scalar-variable is not declared.

Thanks and regards,

Stefan

""Walter Wang [MSFT]"" <wawang (AT) online (DOT) microsoft.com> schrieb im Newsbeitrag
news:KjKD7aNMIHA.5204 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl...
Quote:
Hi Stefan,

This is a quick note to let you know that I am performing research on this
issue and will get back to you as soon as possible. I appreciate your
patience.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.




Reply With Quote
  #4  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default Re: Problem creating TemplateFields in DetailsView dynamically - 12-04-2007 , 09:24 PM



Hi Stefan,

Just a quick note to let you know that I'm still here to help if you find
the solution doesn't work for you.

Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.