Question about RepeaterItem

T

TT

Hi,
I have a repeater (rpt1) in my website, and I want to read all the
data when button (btnSubmit) click.
There is one thing that I don't understand.
When I add "For each item in rpt1.items" in btnSubmit_click, the item
count of rpt1 will become to 0.
But if I add "For each item in rpt1.items" in page_load, it will not.
Is anyone know why?

These are some of my codes, thank you for your help.

[.aspx]
<table>
<tr> <td>.... </td> </tr>
<tr> <td>.... </td> </tr>
<tr>
<td>
<table>
<asp:Repeater ID="rptLIST" Runat="server"
OnItemDataBound="rptLIST_ItemDataBound">
<HeaderTemplate>
<tr>
<td class="FIELDNAMETEXT" align="left" valign="top">Samp#</
td>
<td class="FIELDNAMETEXT" align="left" valign="top">Sample
code</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="FIELDDATATEXT" align="left" valign="top">
<asp:Label ID="lblSAMPNO" Runat="server"></asp:Label>
</td>
<td class="FIELDNAMETEXT" align="left" valign="top">
<asp:TextBox ID="txtSAMPCODE" Runat="server" MaxLength="5"
Width="50"></asp:TextBox>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</td>
</tr>
<tr>
<td align="left" valign="top" class="FIELDNAMETEXT">
<asp:Button ID="btnSUBDETAIL" Runat="server" Text="Submit"></
asp:Button>
</td>
</tr>
</table>


[.aspx.vb - 1. add in page]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dim item as RepeaterItem
If Not Page.IsPostBack Then
...
Else
For Each item In rptLIST.Items
...
Next item
End If
End Sub

[.aspx.vb - 2. or add in button_click]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dim item as RepeaterItem
If Not Page.IsPostBack Then
...
End If
End Sub

Protected Sub btnSUBDETAIL_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSUBDETAIL.Click
dim item as RepeaterItem

For Each item In rptLIST.Items
...
Next item
End Sub
 
T

Teemu Keiski

Hi,

can you show a bit more of the code in which you databind the Repeater? Are
you sure you don't accidentally redatabind the repeater, or that you don't
haveViewState disabled at the Page level?
 
T

TT

Hi,
"ViewState disabled at the Page level"?
Sorry, I have no idea what it is.

I did try to run it with breakpoints at all over the functions.
I am sure I didn't accidentally redatabind the repeater.

These are the codes that I use in databind:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dim item as RepeaterItem
If Not Page.IsPostBack Then
....
Detail_Get()
....
Else
For Each item In rptLIST.Items
...
Next item
End If
End Sub

Private Sub Detail_Get()
Dim oAdapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim tempStr As String

'-- set repeater to blank
rptLIST.DataSource = Nothing
rptLIST.DataBind()

oCmd = New OleDbCommand("SPEC_DETGet", oCon)
oCmd.CommandType = CommandType.StoredProcedure

MAddSProcParm(oCmd, "i_specid", "Integer", 7, "Input", sSPECID)

Try
oAdapter.SelectCommand = oCmd
oAdapter.TableMappings.Add("Table", "Data")
oAdapter.Fill(ds)

If ds.Tables(0).Rows.Count > 0 Then
tempStr = CType(ds.Tables(0).Rows(0),
System.Data.DataRow).ItemArray(0).ToString()
If tempStr = "OK" Then
tempStr = ""
rptLIST.DataSource = ds
rptLIST.DataBind()
End If
End If
Catch objError As Exception
tempStr = objError.Message & "<br>" & objError.Source
Finally
If Not oAdapter Is Nothing Then
oAdapter.Dispose()
End If
If Not oCmd Is Nothing Then
oCmd.Dispose()
oCmd = Nothing
End If
End Try

If tempStr <> "" And tempStr <> "OK" Then
pMSGERR.AddError(tempStr)
End If
End Sub

Protected Sub rptLIST_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
rptLIST.ItemDataBound
Dim tStr As String
Dim CalNum As Double
Dim DateIn As DateTime

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
CType(e.Item.FindControl("lblSAMPNO"), Label).Text =
CType(e.Item.DataItem, DataRowView).Item("SAMPNO").ToString()

CType(e.Item.FindControl("txtSAMPCODE"), TextBox).Text =
CType(e.Item.DataItem, DataRowView).Item("SAMPCODE").ToString()
.......
End Select
End Sub
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top