Highlighted
Absent Member.
Absent Member.
1881 views

OnItemDataBound in asp:Repeater

Jump to solution

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

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: OnItemDataBound in asp:Repeater

Jump to solution

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.

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: OnItemDataBound in asp:Repeater

Jump to solution

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.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: OnItemDataBound in asp:Repeater

Jump to solution

Thanks Chris 🙂

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.