What is the Best Practice for binding Controls [Data in the data grid is to be binded with the controls of some form ] ?

Showing Answers 1 - 2 of 2 Answers

public partial class UseDataList : System.Web.UI.Page
{
   protected DataTable GetInventory()
   {

      String strConnection =
      @"Provider=Microsoft.Jet.OLEDB.4.0;
      DataSource=C:\\northwind.mdb";

      DbProviderFactory f =
           DbProviderFactories.GetFactory("System.Data.OleDb");

      DbConnection connection = f.CreateConnection();
      connection.ConnectionString = strConnection;

      connection.Open();

      DbCommand command = f.CreateCommand();
      command.CommandText = "Select * from DotNetReferences";
      command.Connection = connection;

      IDataReader reader = command.ExecuteReader();

      DataTable dt = new DataTable();
      dt.Load(reader);
      reader.Close();
      connection.Close();
      connection.Dispose();

      return dt;
   }

   protected DataTable BindToinventory()
   {
      DataTable dt;
      dt = this.GetInventory();
      this.DataList1.DataSource = dt;
      this.DataBind();
      return dt;
   }

  Was this answer useful?  Yes

 

Some user controls are entirely self contained, for example, a user control displaying current stock quotes does not need to interact with any other content on the page. Other user controls will contain buttons to post back. Although it is possible to subscribe to the button click event from the containing page, doing so would break some of the object oriented rules of encapsulation. A better idea is to publish an event in the user control to allow any interested parties to handle the event.

This technique is commonly referred to as ?event bubbling? since the event can continue to pass through layers, starting at the bottom (the user control) and perhaps reaching the top level (the page) like a bubble moving up a champagne glass.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions