OnItemDataBound in asp:Repeater

Hello,
Can anyone please provide a simple example to use the onItemDataBound event in asp:Repeater using Visual Cobol. Thanks in advance.

Parents
  • Verified Answer

    The following is an example that shows the repeater control on an ASP.NET form and the code behind to implement it. The Repeater control is wired up to the OnItemDataBound event to modify the content of each entry to add a hyperlink using the ID of a customer row in the Northwind Customer database.

    This example assumes that you have a SQL Server connection defined in your web.config file.

    And the code behind...

          $set ilusing"System.Data.SqlClient"
          $set ilusing"System.Configuration"
          $set ilusing"System.Data"
     
           class-id testrepeater._Default is partial     
                   inherits type System.Web.UI.Page public.
           working-storage section.
               
           method-id Page_Load protected.
           local-storage section.
           procedure division using by value sender as object by value e as type EventArgs.
               invoke GetCustomers
               goback.           
           end method.
           method-id GetCustomers private.
           procedure division.
               *>Connection String From Web.Config File
               declare con as type SqlConnection = new SqlConnection(type ConfigurationManager::ConnectionStrings["mycon"]::ConnectionString)
               declare dt as type DataTable = new DataTable
               *>give commadText and connection to it 
               declare adp as type SqlDataAdapter = new SqlDataAdapter("SELECT * FROM Customers", con)
               invoke adp::Fill(dt)
               set Repeater1::DataSource to dt
               invoke Repeater1::DataBind
               goback.
           end method.       
           method-id Repeater1_ItemDataBound protected.
           procedure division using by value sender as object e as type System.Web.UI.WebControls.RepeaterItemEventArgs.
               declare myID as string = type DataBinder::Eval(e::Item::DataItem, "CustomerID")::ToString
               declare hp as type HyperLink = e::Item::FindControl("link") as type HyperLink
               set hp::NavigateUrl = "~/default.apx?page=" & myID
    
           end method.
    
           end class.
    
Reply
  • Verified Answer

    The following is an example that shows the repeater control on an ASP.NET form and the code behind to implement it. The Repeater control is wired up to the OnItemDataBound event to modify the content of each entry to add a hyperlink using the ID of a customer row in the Northwind Customer database.

    This example assumes that you have a SQL Server connection defined in your web.config file.

    And the code behind...

          $set ilusing"System.Data.SqlClient"
          $set ilusing"System.Configuration"
          $set ilusing"System.Data"
     
           class-id testrepeater._Default is partial     
                   inherits type System.Web.UI.Page public.
           working-storage section.
               
           method-id Page_Load protected.
           local-storage section.
           procedure division using by value sender as object by value e as type EventArgs.
               invoke GetCustomers
               goback.           
           end method.
           method-id GetCustomers private.
           procedure division.
               *>Connection String From Web.Config File
               declare con as type SqlConnection = new SqlConnection(type ConfigurationManager::ConnectionStrings["mycon"]::ConnectionString)
               declare dt as type DataTable = new DataTable
               *>give commadText and connection to it 
               declare adp as type SqlDataAdapter = new SqlDataAdapter("SELECT * FROM Customers", con)
               invoke adp::Fill(dt)
               set Repeater1::DataSource to dt
               invoke Repeater1::DataBind
               goback.
           end method.       
           method-id Repeater1_ItemDataBound protected.
           procedure division using by value sender as object e as type System.Web.UI.WebControls.RepeaterItemEventArgs.
               declare myID as string = type DataBinder::Eval(e::Item::DataItem, "CustomerID")::ToString
               declare hp as type HyperLink = e::Item::FindControl("link") as type HyperLink
               set hp::NavigateUrl = "~/default.apx?page=" & myID
    
           end method.
    
           end class.
    
Children
No Data