Link to home
Start Free TrialLog in
Avatar of karinos57
karinos57Flag for Afghanistan

asked on

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.
Avatar of karinos57
karinos57
Flag of Afghanistan image

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
actually i figured out, i was missing single quotes around the text box.  thanks
thnx