|
Home > Archive > Microsoft Content Management Server > February 2004 > DataGrid in an HTMLPlaceholder Control
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
DataGrid in an HTMLPlaceholder Control
|
|
| Chandy 2004-02-26, 5:35 pm |
| Hi all,
We are having problems with a new Placeholder control derived from the
HtmlPlaceholderControl. We are using a DataGrid inside the
PlaceholderControl to display XML which is stored in the Placeholder
as a string so that it can be manipulated. We cannot use the
XMLPlaceholder control as we need to be able to launch the MCMS tree
and resource gallery controls from within our control to update the
values in the grid. We add a TemplateColumn to the DataGrid to give
us potential Delete functionality and have a FooterTemplate to allow
us to add new rows to the DataSet behind the grid.
On saving the content or inserting a column, the data should be saved.
We found that we could not do this directly anywhere but in the
SavePlaceholderContent method of the PlaceholderControl. To get
around this we 'stage' the content to a Class member called
htmlContent and update that until it comes time to save. This is
HtmlEncoded and HtmlDecoded on-the-fly to allow it to be stored in the
HTMLPlaceholder.
When we create a new posting from a template containing our new
control, in authoring mode, the DataGrid is displayed with our default
data (we add some default XML to do this if none is present in the
LoadPlaceholderContentForAuthoring method). We can then insert a new
row and the page refreshes with our new row in place. At this point,
if we either try to save the page or add another row, the entire
placeholder gets reset back to the starting point of just our default
XML for content. Debugging has shown that the Placeholder does not
contain any data at this point! Under some conditions the grid is
displayed twice, side-by-side, though hitting 'Insert' then takes us
back to the single grid.
We have been all over examples from Stefan and others but we just
can't figure out what's wrong. The code as we have it just now is
attached below. Comments/advice/ideas are very welcome! Apologies
for line wrapping and lack of comments but you should get the idea!
Thanks!
Chandy
Code:
========================================
=
Option Explicit On
Option Strict On
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Web.UI.WebControls
Imports Microsoft.ContentManagement.Publishing
Imports Microsoft.ContentManagement.Publishing.Extensions.Placeholders
Imports Microsoft.ContentManagement.Publishing.Extensions.Placeholders.XmlPlaceholderDefinition
Imports Microsoft.ContentManagement.WebControls.Design
Imports Microsoft.ContentManagement.WebControls
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web
Imports System.IO
Namespace CustomControls
<DefaultProperty("Text"), _
ToolboxData("<{0}:GridPlaceholder
runat=server></{0}:GridPlaceholder>"), _
Designer("CustomControlsDesigners.GridPlaceholderDesigner"), _
SupportedPlaceholderDefinitionType(GetTy
pe(HtmlPlaceholderDefinition))>
_
Public Class GridPlaceholder
Inherits HtmlPlaceholderControl
#Region "Private"
Private WithEvents dgPostings As DataGrid
Private PresentationControl As TextBox
Private WithEvents itemPosting_footer As TextBox
Private WithEvents itemImage_footer As TextBox
Private htmlContent As String
#End Region
#Region "Properties"
#End Region
Public Sub New()
End Sub
#Region "DataGridTemplate"
Private Class DataGridTemplate
Implements ITemplate
Dim templateType As ListItemType
Dim columnName As String
Sub New(ByVal type As ListItemType, ByVal colName As
String)
templateType = type
columnName = colName
End Sub
Sub InstantiateIn(ByVal container As Control) _
Implements ITemplate.InstantiateIn
Dim lc As New Literal
Dim cellData As New TextBox
Dim footerText As New TextBox
Select Case templateType
Case ListItemType.Header
lc.Text = "<B>" & columnName & "</B>"
container.Controls.Add(lc)
Case ListItemType.Item
If Not columnName = "" Then
AddHandler cellData.DataBinding, AddressOf
BindStringColumn
container.Controls.Add(cellData)
Dim editLink As New
HtmlControls.HtmlAnchor
editLink.ID = columnName
editLink.InnerText = "Edit"
editLink.HRef = "#"
container.Controls.Add(editLink)
Else
Dim deleteButton As New System.Web.UI.WebControls.Button
deleteButton.ID = "delete"
deleteButton.CommandName = "Delete"
deleteButton.Text = "Delete"
container.Controls.Add(deleteButton)
End If
Case ListItemType.EditItem
Dim tb As New TextBox
tb.Text = ""
container.Controls.Add(tb)
Case ListItemType.Footer
If Not columnName = "" Then
footerText.ID = columnName & "_footer"
container.Controls.Add(footerText)
' if action column
Else
Dim insertButton As New System.Web.UI.WebControls.Button
insertButton.ID = "insert"
insertButton.CommandName = "Insert"
insertButton.Text = "Insert"
container.Controls.Add(insertButton)
End If
End Select
End Sub
Sub BindStringColumn(ByVal sender As Object, ByVal e As
EventArgs)
Dim txtValue As TextBox = CType(sender, TextBox)
Dim Container As DataGridItem = CType(txtValue.NamingContainer,
DataGridItem)
txtValue.Text = CType(DataBinder.Eval(Container.DataItem, columnName),
String)
End Sub
End Class
#End Region
#Region "Authoring Controls"
Protected Overrides Sub CreateAuthoringChildControls(ByVal
authoringContainer _ As
Microsoft.ContentManagement.WebControls.BaseModeContainer)
(MyBase.BoundPlaceholder, HtmlPlaceholder)
dgPostings = New DataGrid
authoringContainer.Controls.Add(dgPostings)
If Page.IsPostBack Then
Dim e As Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs
LoadPlaceholderContentForAuthoring(e)
End If
End Sub
Protected Overrides Sub LoadPlaceholderContentForAuthoring(ByVal
e As
Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs)
EnsureChildControls()
Dim myPlaceholder As HtmlPlaceholder =
CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
htmlContent = myPlaceholder.Html
' if new posting create defaults
If htmlContent = String.Empty Then
Dim defContent As String = "<?xml version=""1.0""
?><data><item><itemposting></itemposting><itemimage></itemimage></item></data>"
defContent =
HttpContext.Current.Server.HtmlEncode(defContent)
htmlContent = defContent
End If
'Me.dgPostings = New DataGrid
dgPostings.ID = "PostingsDataGrid"
'Me.dgPostings.Height =
System.Web.UI.WebControls.Unit.Pixel(250)
'Me.dgPostings.Width =
System.Web.UI.WebControls.Unit.Pixel(500)
'Me.dgPostings.BorderStyle = BorderStyle.Double
dgPostings.ShowFooter = True
dgPostings.AutoGenerateColumns = False
' baseAuthoringContainer.Controls.Add(Me.dgPostings)
Dim postingColumn As New TemplateColumn
postingColumn.HeaderTemplate = New
DataGridTemplate(ListItemType.Header, "Posting Link")
postingColumn.ItemTemplate = New
DataGridTemplate(ListItemType.Item, "itemposting")
postingColumn.EditItemTemplate = New
DataGridTemplate(ListItemType.EditItem, "itemposting")
postingColumn.FooterTemplate = New
DataGridTemplate(ListItemType.Footer, "itemposting")
dgPostings.Columns.Add(postingColumn)
Dim imageColumn As New TemplateColumn
imageColumn.HeaderTemplate = New
DataGridTemplate(ListItemType.Header, "Image Link")
imageColumn.ItemTemplate = New
DataGridTemplate(ListItemType.Item, "itemimage")
imageColumn.EditItemTemplate = New
DataGridTemplate(ListItemType.EditItem, "itemimage")
imageColumn.FooterTemplate = New
DataGridTemplate(ListItemType.Footer, "itemimage")
dgPostings.Columns.Add(imageColumn)
Dim insertColumn As New TemplateColumn
insertColumn.ItemTemplate = New
DataGridTemplate(ListItemType.Item, "")
insertColumn.FooterTemplate = New
DataGridTemplate(ListItemType.Footer, "")
dgPostings.Columns.Add(insertColumn)
dgPostings.DataSource = getContentAsDataset()
dgPostings.DataBind()
End Sub
#End Region
#Region "Presentation Controls"
Protected Overrides Sub CreatePresentationChildControls(ByVal
presentationContainer As
Microsoft.ContentManagement.WebControls.BaseModeContainer)
PresentationControl = New TextBox
PresentationControl.ID = "DisplayString"
presentationContainer.Controls.Add(PresentationControl)
End Sub
Protected Overrides Sub
LoadPlaceholderContentForPresentation(By
Val e As
Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs)
EnsureChildControls()
Dim myPlaceholder As HtmlPlaceholder =
CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
Dim myContent As String
myContent = getContentAsDataset().ToString
PresentationControl.Text = myContent
End Sub
#End Region
#Region "SavePlaceHolderContent"
Protected Overrides Sub SavePlaceholderContent(ByVal e As
Microsoft.ContentManagement.WebControls.PlaceholderControlSaveEventArgs)
EnsureChildControls()
MyBase.SavePlaceholderContent(e)
Dim myPlaceholder As HtmlPlaceholder =
CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
Dim myDataSet As DataSet
myDataSet = getDatasetFromDataGrid(dgPostings)
saveDataSet(myDataSet)
saveToPlaceholder(myPlaceholder)
End Sub
#End Region
#Region "dataGridItemCommand"
Private Sub dgPostings_ItemCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim myPlaceholder As HtmlPlaceholder =
CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
Dim txtItemPosting As TextBox
Dim strItemPosting As String
Dim txtItemImage As TextBox
Dim strItemImage As String
Dim myDataGrid As DataGrid
Dim myDataSet As DataSet
Dim myDataRow As DataRow
'Read in the values of the TextBoxes
txtItemPosting =
CType(e.Item.FindControl("itemPosting_footer"),
System.Web.UI.WebControls.TextBox)
strItemPosting = txtItemPosting.Text
txtItemImage =
CType(e.Item.FindControl("itemImage_footer"),
System.Web.UI.WebControls.TextBox)
strItemImage = txtItemImage.Text
myDataGrid = CType(e.Item.Parent.Parent, DataGrid)
myDataSet = CType(myDataGrid.DataSource,
System.Data.DataSet)
'create new row
myDataRow = myDataSet.Tables(0).NewRow
myDataRow("itemPosting") = strItemPosting
myDataRow("itemImage") = strItemImage
'add new row to dataset
myDataSet.Tables(0).Rows.Add(myDataRow)
'Dim myXmlReader As XmlReader
' Me.contentData = myDataSet.ReadXml()
saveDataSet(myDataSet)
saveToPlaceholder(myPlaceholder)
CType(e.Item.Parent.Parent, DataGrid).DataSource =
myDataSet
CType(e.Item.Parent.Parent, DataGrid).DataBind()
End If
End Sub
Private Sub dgPostings_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dgPostings.Init
AddHandler dgPostings.ItemCommand, AddressOf
dgPostings_ItemCommand
End Sub
#End Region
#Region "Data Functions"
Private Function getDatasetFromDataGrid(ByVal dg As DataGrid)
As DataSet
Dim myDataSet As DataSet
myDataSet = CType(dg.DataSource, System.Data.DataSet)
Return myDataSet
End Function
Private Function getContentAsDataset() As DataSet
Dim placeholderContent As String
Dim myStrReader As StringReader
Dim myDataset As DataSet
placeholderContent =
HttpContext.Current.Server.HtmlDecode(htmlContent)
myStrReader = New StringReader(placeholderContent)
myDataset = New DataSet
myDataset.ReadXml(myStrReader)
Return myDataset
End Function
Private Sub saveDataSet(ByVal ds As DataSet)
htmlContent =
HttpContext.Current.Server.HtmlEncode(ds.GetXml())
End Sub
Private Sub saveToPlaceholder(ByVal p As HtmlPlaceholder)
p.Html = htmlContent
End Sub
#End Region
End Class
End Namespace
Namespace CustomControlsDesigners
#Region "GridPlaceholderDesigner"
Public Class GridPlaceholderDesigner
Inherits System.Web.UI.Design.ControlDesigner
#Region "Public Methods"
Public Overrides Function GetDesignTimeHtml() As String
Return Me.GetEmptyDesignTimeHtml
End Function
#End Region
End Class
#End Region
End Namespace
=====================================
End of Code
| |
| Stefan [MSFT] 2004-02-26, 8:35 pm |
| Hi Chandy,
first of all: please disable all try-catch blocks in your control in order
to see potential errors which are silently catched.
Maybe the change of the datagrid modifies the viewstate and a viewstate
error is hidden this way?
Cheers,
Stefan.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Chandy" <chandy@totalise.co.uk> wrote in message
news:5af0375a.0402261429.6fd6df62@posting.google.com...
> Hi all,
>
> We are having problems with a new Placeholder control derived from the
> HtmlPlaceholderControl. We are using a DataGrid inside the
> PlaceholderControl to display XML which is stored in the Placeholder
> as a string so that it can be manipulated. We cannot use the
> XMLPlaceholder control as we need to be able to launch the MCMS tree
> and resource gallery controls from within our control to update the
> values in the grid. We add a TemplateColumn to the DataGrid to give
> us potential Delete functionality and have a FooterTemplate to allow
> us to add new rows to the DataSet behind the grid.
>
> On saving the content or inserting a column, the data should be saved.
> We found that we could not do this directly anywhere but in the
> SavePlaceholderContent method of the PlaceholderControl. To get
> around this we 'stage' the content to a Class member called
> htmlContent and update that until it comes time to save. This is
> HtmlEncoded and HtmlDecoded on-the-fly to allow it to be stored in the
> HTMLPlaceholder.
>
> When we create a new posting from a template containing our new
> control, in authoring mode, the DataGrid is displayed with our default
> data (we add some default XML to do this if none is present in the
> LoadPlaceholderContentForAuthoring method). We can then insert a new
> row and the page refreshes with our new row in place. At this point,
> if we either try to save the page or add another row, the entire
> placeholder gets reset back to the starting point of just our default
> XML for content. Debugging has shown that the Placeholder does not
> contain any data at this point! Under some conditions the grid is
> displayed twice, side-by-side, though hitting 'Insert' then takes us
> back to the single grid.
>
> We have been all over examples from Stefan and others but we just
> can't figure out what's wrong. The code as we have it just now is
> attached below. Comments/advice/ideas are very welcome! Apologies
> for line wrapping and lack of comments but you should get the idea!
>
> Thanks!
>
> Chandy
>
>
> Code:
> ========================================
=
> Option Explicit On
> Option Strict On
>
> Imports System.Xml
> Imports System.Xml.Xsl
> Imports System.Web.UI.WebControls
> Imports Microsoft.ContentManagement.Publishing
> Imports Microsoft.ContentManagement.Publishing.Extensions.Placeholders
> Imports
Microsoft.ContentManagement.Publishing.Extensions.Placeholders.XmlPlaceholde
rDefinition
> Imports Microsoft.ContentManagement.WebControls.Design
> Imports Microsoft.ContentManagement.WebControls
> Imports System.ComponentModel
> Imports System.Web.UI
> Imports System.Web
> Imports System.IO
>
> Namespace CustomControls
>
>
> <DefaultProperty("Text"), _
> ToolboxData("<{0}:GridPlaceholder
> runat=server></{0}:GridPlaceholder>"), _
> Designer("CustomControlsDesigners.GridPlaceholderDesigner"), _
> SupportedPlaceholderDefinitionType(GetTy
pe(HtmlPlaceholderDefinition))>
> _
> Public Class GridPlaceholder
> Inherits HtmlPlaceholderControl
>
> #Region "Private"
> Private WithEvents dgPostings As DataGrid
> Private PresentationControl As TextBox
>
>
> Private WithEvents itemPosting_footer As TextBox
> Private WithEvents itemImage_footer As TextBox
> Private htmlContent As String
>
> #End Region
>
> #Region "Properties"
>
> #End Region
>
> Public Sub New()
>
> End Sub
>
> #Region "DataGridTemplate"
>
> Private Class DataGridTemplate
> Implements ITemplate
> Dim templateType As ListItemType
> Dim columnName As String
>
> Sub New(ByVal type As ListItemType, ByVal colName As
> String)
> templateType = type
> columnName = colName
> End Sub
>
> Sub InstantiateIn(ByVal container As Control) _
> Implements ITemplate.InstantiateIn
> Dim lc As New Literal
> Dim cellData As New TextBox
> Dim footerText As New TextBox
>
>
> Select Case templateType
> Case ListItemType.Header
> lc.Text = "<B>" & columnName & "</B>"
> container.Controls.Add(lc)
> Case ListItemType.Item
>
>
> If Not columnName = "" Then
> AddHandler cellData.DataBinding, AddressOf
> BindStringColumn
> container.Controls.Add(cellData)
> Dim editLink As New
> HtmlControls.HtmlAnchor
> editLink.ID = columnName
> editLink.InnerText = "Edit"
> editLink.HRef = "#"
> container.Controls.Add(editLink)
> Else
> Dim deleteButton As New System.Web.UI.WebControls.Button
> deleteButton.ID = "delete"
> deleteButton.CommandName = "Delete"
> deleteButton.Text = "Delete"
> container.Controls.Add(deleteButton)
> End If
>
>
> Case ListItemType.EditItem
> Dim tb As New TextBox
> tb.Text = ""
> container.Controls.Add(tb)
> Case ListItemType.Footer
> If Not columnName = "" Then
> footerText.ID = columnName & "_footer"
> container.Controls.Add(footerText)
> ' if action column
> Else
> Dim insertButton As New System.Web.UI.WebControls.Button
> insertButton.ID = "insert"
> insertButton.CommandName = "Insert"
> insertButton.Text = "Insert"
> container.Controls.Add(insertButton)
> End If
> End Select
> End Sub
>
> Sub BindStringColumn(ByVal sender As Object, ByVal e As
> EventArgs)
>
> Dim txtValue As TextBox = CType(sender, TextBox)
> Dim Container As DataGridItem = CType(txtValue.NamingContainer,
> DataGridItem)
> txtValue.Text = CType(DataBinder.Eval(Container.DataItem, columnName),
> String)
> End Sub
>
> End Class
>
> #End Region
>
> #Region "Authoring Controls"
>
> Protected Overrides Sub CreateAuthoringChildControls(ByVal
> authoringContainer _ As
> Microsoft.ContentManagement.WebControls.BaseModeContainer)
> (MyBase.BoundPlaceholder, HtmlPlaceholder)
>
> dgPostings = New DataGrid
> authoringContainer.Controls.Add(dgPostings)
>
> If Page.IsPostBack Then
> Dim e As
Microsoft.ContentManagement.WebControls. PlaceholderControlEventArgs
> LoadPlaceholderContentForAuthoring(e)
> End If
>
> End Sub
>
>
> Protected Overrides Sub LoadPlaceholderContentForAuthoring(ByVal
e As
> Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs)
> EnsureChildControls()
> Dim myPlaceholder As HtmlPlaceholder =
> CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
>
> htmlContent = myPlaceholder.Html
>
> ' if new posting create defaults
> If htmlContent = String.Empty Then
> Dim defContent As String = "<?xml version=""1.0""
>
?><data><item><itemposting></itemposting><itemimage></itemimage></item></dat
a>"
> defContent =
> HttpContext.Current.Server.HtmlEncode(defContent)
> htmlContent = defContent
> End If
>
>
>
> 'Me.dgPostings = New DataGrid
> dgPostings.ID = "PostingsDataGrid"
> 'Me.dgPostings.Height =
> System.Web.UI.WebControls.Unit.Pixel(250)
> 'Me.dgPostings.Width =
> System.Web.UI.WebControls.Unit.Pixel(500)
> 'Me.dgPostings.BorderStyle = BorderStyle.Double
> dgPostings.ShowFooter = True
> dgPostings.AutoGenerateColumns = False
>
> ' baseAuthoringContainer.Controls.Add(Me.dgPostings)
>
> Dim postingColumn As New TemplateColumn
> postingColumn.HeaderTemplate = New
> DataGridTemplate(ListItemType.Header, "Posting Link")
> postingColumn.ItemTemplate = New
> DataGridTemplate(ListItemType.Item, "itemposting")
> postingColumn.EditItemTemplate = New
> DataGridTemplate(ListItemType.EditItem, "itemposting")
> postingColumn.FooterTemplate = New
> DataGridTemplate(ListItemType.Footer, "itemposting")
> dgPostings.Columns.Add(postingColumn)
>
> Dim imageColumn As New TemplateColumn
> imageColumn.HeaderTemplate = New
> DataGridTemplate(ListItemType.Header, "Image Link")
> imageColumn.ItemTemplate = New
> DataGridTemplate(ListItemType.Item, "itemimage")
> imageColumn.EditItemTemplate = New
> DataGridTemplate(ListItemType.EditItem, "itemimage")
> imageColumn.FooterTemplate = New
> DataGridTemplate(ListItemType.Footer, "itemimage")
> dgPostings.Columns.Add(imageColumn)
>
> Dim insertColumn As New TemplateColumn
> insertColumn.ItemTemplate = New
> DataGridTemplate(ListItemType.Item, "")
> insertColumn.FooterTemplate = New
> DataGridTemplate(ListItemType.Footer, "")
> dgPostings.Columns.Add(insertColumn)
>
> dgPostings.DataSource = getContentAsDataset()
> dgPostings.DataBind()
>
> End Sub
>
>
> #End Region
>
> #Region "Presentation Controls"
>
> Protected Overrides Sub CreatePresentationChildControls(ByVal
> presentationContainer As
> Microsoft.ContentManagement.WebControls.BaseModeContainer)
> PresentationControl = New TextBox
> PresentationControl.ID = "DisplayString"
> presentationContainer.Controls.Add(PresentationControl)
> End Sub
>
> Protected Overrides Sub
> LoadPlaceholderContentForPresentation(By
Val e As
> Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs)
> EnsureChildControls()
> Dim myPlaceholder As HtmlPlaceholder =
> CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
> Dim myContent As String
> myContent = getContentAsDataset().ToString
> PresentationControl.Text = myContent
> End Sub
>
> #End Region
>
> #Region "SavePlaceHolderContent"
> Protected Overrides Sub SavePlaceholderContent(ByVal e As
> Microsoft.ContentManagement.WebControls.PlaceholderControlSaveEventArgs)
> EnsureChildControls()
> MyBase.SavePlaceholderContent(e)
> Dim myPlaceholder As HtmlPlaceholder =
> CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
> Dim myDataSet As DataSet
> myDataSet = getDatasetFromDataGrid(dgPostings)
> saveDataSet(myDataSet)
> saveToPlaceholder(myPlaceholder)
> End Sub
> #End Region
>
> #Region "dataGridItemCommand"
>
> Private Sub dgPostings_ItemCommand(ByVal source As Object,
> ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
> If e.CommandName = "Insert" Then
> Dim myPlaceholder As HtmlPlaceholder =
> CType(MyBase.BoundPlaceholder, HtmlPlaceholder)
> Dim txtItemPosting As TextBox
> Dim strItemPosting As String
> Dim txtItemImage As TextBox
> Dim strItemImage As String
> Dim myDataGrid As DataGrid
> Dim myDataSet As DataSet
> Dim myDataRow As DataRow
>
> 'Read in the values of the TextBoxes
> txtItemPosting =
> CType(e.Item.FindControl("itemPosting_footer"),
> System.Web.UI.WebControls.TextBox)
> strItemPosting = txtItemPosting.Text
>
> txtItemImage =
> CType(e.Item.FindControl("itemImage_footer"),
> System.Web.UI.WebControls.TextBox)
> strItemImage = txtItemImage.Text
>
> myDataGrid = CType(e.Item.Parent.Parent, DataGrid)
> myDataSet = CType(myDataGrid.DataSource,
> System.Data.DataSet)
>
> 'create new row
> myDataRow = myDataSet.Tables(0).NewRow
> myDataRow("itemPosting") = strItemPosting
> myDataRow("itemImage") = strItemImage
>
> 'add new row to dataset
> myDataSet.Tables(0).Rows.Add(myDataRow)
>
> 'Dim myXmlReader As XmlReader
>
> ' Me.contentData = myDataSet.ReadXml()
> saveDataSet(myDataSet)
> saveToPlaceholder(myPlaceholder)
>
>
> CType(e.Item.Parent.Parent, DataGrid).DataSource =
> myDataSet
> CType(e.Item.Parent.Parent, DataGrid).DataBind()
>
>
> End If
> End Sub
>
> Private Sub dgPostings_Init(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles dgPostings.Init
> AddHandler dgPostings.ItemCommand, AddressOf
> dgPostings_ItemCommand
> End Sub
>
> #End Region
>
> #Region "Data Functions"
>
> Private Function getDatasetFromDataGrid(ByVal dg As DataGrid)
> As DataSet
> Dim myDataSet As DataSet
>
> myDataSet = CType(dg.DataSource, System.Data.DataSet)
>
> Return myDataSet
> End Function
>
> Private Function getContentAsDataset() As DataSet
> Dim placeholderContent As String
> Dim myStrReader As StringReader
> Dim myDataset As DataSet
>
> placeholderContent =
> HttpContext.Current.Server.HtmlDecode(htmlContent)
> myStrReader = New StringReader(placeholderContent)
> myDataset = New DataSet
> myDataset.ReadXml(myStrReader)
>
> Return myDataset
> End Function
>
> Private Sub saveDataSet(ByVal ds As DataSet)
> htmlContent =
> HttpContext.Current.Server.HtmlEncode(ds.GetXml())
> End Sub
>
> Private Sub saveToPlaceholder(ByVal p As HtmlPlaceholder)
> p.Html = htmlContent
> End Sub
>
> #End Region
>
> End Class
>
> End Namespace
>
> Namespace CustomControlsDesigners
>
> #Region "GridPlaceholderDesigner"
> Public Class GridPlaceholderDesigner
> Inherits System.Web.UI.Design.ControlDesigner
> #Region "Public Methods"
> Public Overrides Function GetDesignTimeHtml() As String
> Return Me.GetEmptyDesignTimeHtml
> End Function
>
>
> #End Region
>
> End Class
> #End Region
>
> End Namespace
> =====================================
> End of Code
| |
| Chandy 2004-02-27, 4:35 am |
| Hi Stefan,
Your mention of viewstate caused me to enable trace in the web.config.
I did that and everything looked fine until I hit the insert button
in my grid. Then all the trace messages dissapeared and won't come
back even if I close my browser and log-in again!!!!!!
Any ideas??? I'm going to check my page template for clues!
Thanks!
Chandy
"Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message news:<e$hgbVM$DHA.212@TK2MSFTNGP12.phx.gbl>...[color=darkred]
> Hi Chandy,
>
> first of all: please disable all try-catch blocks in your control in order
> to see potential errors which are silently catched.
> Maybe the change of the datagrid modifies the viewstate and a viewstate
> error is hidden this way?
>
> Cheers,
> Stefan.
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> "Chandy" <chandy@totalise.co.uk> wrote in message
> news:5af0375a.0402261429.6fd6df62@posting.google.com...
> Microsoft.ContentManagement.Publishing.Extensions.Placeholders.XmlPlaceholde
> rDefinition
> Microsoft.ContentManagement.WebControls.PlaceholderControlEventArgs
> ?><data><item><itemposting></itemposting><itemimage></itemimage></item></dat
> a>"
| |
| Stefan [MSFT] 2004-02-27, 10:35 am |
| hi Chandy,
this sounds strange - maybe a caching issue?
Add a date output to the template to be sure that you are able to verify
that always the latest version is shown.
Cheers,
Stefan.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Chandy" <chandy@totalise.co.uk> wrote in message
news:5af0375a.0402270124.13425f3c@posting.google.com...
> Hi Stefan,
>
> Your mention of viewstate caused me to enable trace in the web.config.
> I did that and everything looked fine until I hit the insert button
> in my grid. Then all the trace messages dissapeared and won't come
> back even if I close my browser and log-in again!!!!!!
>
> Any ideas??? I'm going to check my page template for clues!
>
> Thanks!
>
> Chandy
>
>
> "Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message
news:<e$hgbVM$DHA.212@TK2MSFTNGP12.phx.gbl>...[color=darkred]
order[color=darkred]
rights.[color=darkred]
Microsoft.ContentManagement.Publishing.Extensions.Placeholders.XmlPlaceholde[color=darkred]
SupportedPlaceholderDefinitionType(GetTy
pe(HtmlPlaceholderDefinition))>[color=darkred]
?><data><item><itemposting></itemposting><itemimage></itemimage></item></dat[color=darkred]
Microsoft.ContentManagement.WebControls. PlaceholderControlSaveEventArgs)[color=d
arkred]
|
|
|
|
|