Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > URGENT - Repeater Control using Dynamic Controls

Reply
Thread Tools

URGENT - Repeater Control using Dynamic Controls

 
 
New User
Guest
Posts: n/a
 
      03-05-2004
I am trying to build a simple user control made up of a single
Repeater control and a bunch of dynamically created data entry
controls. The problem that is occurring however is that I am unable
to get the data back out of these controls on a postback so that I can
update my original dataset. I have a moved a paired down version of
the user control into a simple aspx page for posting here. Please
take a look at it and let me know if the events ar eout of order or if
there is another reason why it is not working. Thanks in advance.
The main issue is the fact that I cannot retrieve the data from the
controls in the "StorePageState" procedure. The FindControl function
returns nothing even though the controls do exist in the Repeater
Item. Thanks in advance.

--------------------------------
HTML FOR webforms1.aspx
--------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="TestPage.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>PagingRepeater</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:repeater id="RepeaterEvaluationCriteria"
runat="server"></asp:repeater><asp:button id="Button1" runat="server"
Text="Postback"></asp:button></form>
</body>
</HTML>

--------------------------------
CODE BEHIND FOR webforms1.aspx
--------------------------------
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents RepeaterEvaluationCriteria As
System.Web.UI.WebControls.Repeater

Protected WithEvents Button1 As System.Web.UI.WebControls.Button


#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.

InitializeComponent()
InitializeRepeaterTemplate()
End Sub

#End Region

Const cCheckBoxName As String = "chkBox"

Private Class TemplateRepeaterCriteria
Implements ITemplate
Dim TemplateType As ListItemType

Sub New(ByVal type As ListItemType)
TemplateType = type
End Sub

Private Sub TemplateControl_DataBinding(ByVal sender As
Object, ByVal e As System.EventArgs)
Dim TableCellCriteria As HtmlTableCell
Dim CheckBoxItem As New CheckBox()
Dim Container As RepeaterItem

TableCellCriteria = CType(sender, HtmlTableCell)
Container = CType(TableCellCriteria.NamingContainer,
RepeaterItem)

CheckBoxItem.ID = cCheckBoxName
CheckBoxItem.Checked = DataBinder.Eval(Container.DataItem,
"selected")
TableCellCriteria.Controls.Add(CheckBoxItem)
End Sub

Sub InstantiateIn(ByVal Container As Control) Implements
ITemplate.InstantiateIn
Const cColumnSpan As String = "1"

Select Case TemplateType
Case ListItemType.Header
Dim TableHeaderCriteria As New Literal()

TableHeaderCriteria.Text = "<TABLE width='100%'
border='0'>"
TableHeaderCriteria.Text += "<TR><TD colspan='" &
cColumnSpan & "'><HR width='100%'></TD></TR>"

Container.Controls.Add(TableHeaderCriteria)

'Cleanup all Header Template objects
TableHeaderCriteria.Dispose()
TableHeaderCriteria = Nothing

Case ListItemType.Item
Dim TableRowCriteria As New HtmlTableRow()
Dim TableCellCriteria As New HtmlTableCell()

'Add Evaluation Item Label Table Cell
TableCellCriteria.NoWrap = True
AddHandler TableCellCriteria.DataBinding,
AddressOf TemplateControl_DataBinding

'Append Label to the Current Table Row
TableRowCriteria.Cells.Add(TableCellCriteria)

Container.Controls.Add(TableRowCriteria)

'Cleanup all Item Template Table Row and Cell
objects
TableRowCriteria.Dispose()
TableRowCriteria = Nothing

TableCellCriteria.Dispose()
TableCellCriteria = Nothing

Case ListItemType.Footer
Dim CriteriaTableFooter As New Literal()

CriteriaTableFooter.Text = "</TABLE>"
Container.Controls.Add(CriteriaTableFooter)

'Cleanup all Footer Template objects
CriteriaTableFooter.Dispose()
CriteriaTableFooter = Nothing

End Select
End Sub
End Class


Sub InitializeRepeaterTemplate()
'Call constructor to build the custom Header template for the
Evaluation Criteria Repeater
RepeaterEvaluationCriteria.HeaderTemplate = New
TemplateRepeaterCriteria(ListItemType.Header)

'Call constructor to build the custom Item (row) template for
the Evaluation Criteria Repeater
RepeaterEvaluationCriteria.ItemTemplate = New
TemplateRepeaterCriteria(ListItemType.Item)

'Call constructor to build the custom Footer template for the
Evaluation Criteria Repeater
RepeaterEvaluationCriteria.FooterTemplate = New
TemplateRepeaterCriteria(ListItemType.Footer)
End Sub


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If (Not IsPostBack) Then
Load_Data()
Else
StorePageState()
End If

Bind_Repeater_Data()

End Sub

Private Sub Load_Data()

Dim tb As DataTable = New DataTable()
tb.Columns.Add("selected")

Dim index As Integer = 0
Dim NewRow As DataRow
Dim i As Integer

For i = 0 To 10
index = i + 1
NewRow = tb.NewRow()

If (i Mod 2 = 0) Then
NewRow("selected") = True
Else
NewRow("selected") = False
End If

tb.Rows.Add(NewRow)
Next

ViewState("TEMP_TABLE") = tb
End Sub

Private Sub Bind_Repeater_Data()

If IsNothing(ViewState("TEMP_TABLE")) Then
Load_Data()
End If

Dim tb As DataTable = CType(ViewState("TEMP_TABLE"),
DataTable)
Dim ttb As DataTable = tb.Clone()
Dim recordcount As Integer = tb.Rows.Count
Dim i As Integer

For i = 0 To tb.Rows.Count - 1
ttb.ImportRow(tb.Rows(i))
Next

RepeaterEvaluationCriteria.DataSource = ttb
RepeaterEvaluationCriteria.DataBind()
End Sub

Private Sub StorePageState()
Dim tb As DataTable = CType(ViewState("TEMP_TABLE"),
DataTable)
Dim chk As CheckBox
Dim row As DataRow
Dim i As Integer

For i = 0 To RepeaterEvaluationCriteria.Items.Count - 1
'PROBLEM HERE!!!!
chk = CType(RepeaterEvaluationCriteria.Items(i).FindCont rol(cCheckBoxName),
CheckBox)
row = tb.Rows(i)
row("selected") = chk.Checked
Next
End Sub

End Class
 
Reply With Quote
 
 
 
 
New User
Guest
Posts: n/a
 
      03-05-2004
My Appologies, In the 5 hours it took for this to be posted I found
that you need to create a databind handler directly on the control
within the ITemplate interface and not on the table cell containing
it. Please disregard
 
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
Dynamic Controls created by Dynamic Controls Ronald ASP .Net 2 01-17-2006 12:44 AM
Dynamic Events from Dynamic Controls on a User Control - Guess What? Broken! mytestemailaccount@gmail.com ASP .Net 5 03-23-2005 05:06 PM
Repeater Using Javascript Referencing a Column in the Repeater rwoo_98@yahoo.com ASP .Net 0 02-26-2005 05:02 PM
Repeater control with nested repeater chris.reed@digus.com ASP .Net 0 02-11-2005 05:10 PM
Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls Denny Smolinski via .NET 247 ASP .Net Web Controls 1 05-04-2004 09:15 PM



Advertisments