Question about RepeaterItem

Discussion in 'ASP .Net Web Controls' started by TT, May 15, 2007.

  1. TT

    TT Guest

    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
     
    TT, May 15, 2007
    #1
    1. Advertising

  2. TT

    Teemu Keiski Guest

    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?


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "TT" <> wrote in message
    news:...
    > 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
    >
     
    Teemu Keiski, May 17, 2007
    #2
    1. Advertising

  3. TT

    TT Guest

    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
     
    TT, May 17, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ric carrasquilla

    Getting DataItem from a RepeaterItem

    ric carrasquilla, Mar 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,903
    ric carrasquilla
    Mar 4, 2004
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    finding repeateritem which matches a fieldvalue

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Jan 4, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,339
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Jan 4, 2005
  3. z. f.

    flushing inside a repeaterItem

    z. f., Jan 30, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    317
    z. f.
    Jan 30, 2005
  4. Peter Rilling
    Replies:
    1
    Views:
    1,021
    =?Utf-8?B?RWx0b24gVw==?=
    May 19, 2005
  5. Replies:
    3
    Views:
    666
Loading...

Share This Page