• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1122
  • Last Modified:

how to use Repeater in ASP

Hi I am trying to use a repeater in my page.  It is very simple i have a table in my sql server and i am using 2 fields from that table but i can't seem to bind the data in the data set.  I am getting an error at these lines
  Text=<%# DataBinder.Eval(Container.DataItem, "Post_ID")%>/>
Text=<%# DataBinder.Eval(Container.DataItem, "Root_Cause_Analysis") %> />
CommandName=<%# DataBinder.Eval(Container.DataItem, "Button") %>
        Text=<%# DataBinder.Eval(Container.DataItem, "Button")%> />

here is my code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Repeater Tester</title>
</head>

<body>
    <form id="form1" runat="server">
    <div>
   
   
        <asp:Repeater
        ID="Repeater1"
        OnItemCommand="Button_ItemCommand"
        runat="server"
        DataSourceID="RepeaterDataSource">
       
       

        <HeaderTemplate>
        <table>
       <tr>
       <th>Post_ID</th>
       <th>Root_Cause_Analysis</th>
       </tr>
        </HeaderTemplate>
        <ItemTemplate>
        <tr>
        <td>
        <asp:TextBox
        ID="txtPostID"
        runat="server"
       
        Text=<%# DataBinder.Eval(Container.DataItem, "Post_ID")%>/>
           
        </td>
        <td>
        <asp:TextBox
        ID="txtRCA"
        runat="server"
        Text=<%# DataBinder.Eval(Container.DataItem, "Root_Cause_Analysis") %> />
        </td>

        <td>
        <asp:Button
        runat="server"
        ID="btnGeneral"
        CommandName=<%# DataBinder.Eval(Container.DataItem, "Button") %>
        Text=<%# DataBinder.Eval(Container.DataItem, "Button")%> />
        </td>
        </tr>
        </ItemTemplate>
        <FooterTemplate>
        </table>
        </FooterTemplate>
        </asp:Repeater>
       

        <asp:SqlDataSource ID="RepeaterDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:DSRConnectionString %>"
            SelectCommand="SELECT [Post_ID], [Root_Cause_Analysis] FROM [RCA_Detailed_Info]">
        </asp:SqlDataSource>



        </div>
    </form>
</body>

</html>

I AM SIMPLY TRYING TO DO EXACTLY WHAT THIS VIDEO IS SHOWING IN THIS LINK:
http://www.youtube.com/watch?v=KjvHwPQD1gA

 thanks.
0
karinos57
Asked:
karinos57
  • 3
1 Solution
 
karinos57Author Commented:
here is my code behind in which i am having to reproduce the AddColumn function:

Imports System.Data
Imports System.Data.SqlClient

Partial Class test
    Inherits System.Web.UI.Page

    Dim dsDummy As DataSet
    Dim tbDummy As DataTable


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        dsDummy = New DataSet()
        tbDummy = New DataTable()

        If Not Page.IsPostBack Then
            AddColumn()
            tbDummy.Rows.Add("", "", "Add")
            dsDummy.Tables.Add(tbDummy)
            Repeater1.DataSource = dsDummy
            Repeater1.DataBind()


        End If
    End Sub
    Sub Button_ItemCommand(ByVal Sender As Object, ByVal e As RepeaterCommandEventArgs)
        Dim item As RepeaterItem
        AddColumns()
        If e.CommandName = "Add" Then

            For Each item In Repeater1.Items
                Dim stitle As String = CType(item.FindControl("txtRCA"), TextBox).Text
                Dim sISBN As String = CType(item.FindControl("txtPostID"), TextBox).Text
                tbDummy.Rows.Add(stitle, sISBN, "Remove")

            Next

        ElseIf e.CommandName = "Remove" Then
            Dim stitle, sISBN As String

            For Each item In Repeater1.Items
                stitle = CType(item.FindControl("txtRCA"), TextBox).Text
                sISBN = CType(item.FindControl("txtPostID"), TextBox).Text

                Dim btnCurrentEntry As Button = CType(item.FindControl("btnGeneral"), Button)

                If btnCurrentEntry IsNot e.CommandSource Then
                    If btnCurrentEntry.Text = "Remove" Then
                        tbDummy.Rows.Add(stitle, sISBN, "Remove")
                    End If
                End If


            Next


        End If
    End Sub


End Class

any help will be appreciated.  thanks
0
 
informaniacCommented:
Tried removing this ? DataSourceID="RepeaterDataSource"
0
 
karinos57Author Commented:
actually i figured out, i was missing single quotes around the text box.  thanks
0
 
karinos57Author Commented:
thnx
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now