• Object DataSource Update

    Assume you create a grid that shows a list of EmployeeDetails objects. You also add a column with edit links. When the user commits an edit, the GridView fills the ObjectDataSource.UpdateParameters collection with one parameter for each property of the EmployeeDetails class, including EmployeeID, FirstName, LastName, and TitleOfCourtesy. Then, the ObjectDataSource searches for a method named UpdateEmployee() in the EmployeeDB class. This method must have the same parameters, with the same names. That means this method is a match:

  • Parameterized Constructor of ObjectDataSource

    Some time if the ObjectDataSource need a parameter instructor you can supply it in the ObjectCreating event.

  • Databinding life cycle

    1. The page object is created (based on the .aspx file).
    2. The page life cycle begins, and the Page.Init and Page.Load events fire.
    3. All other control events fire.
    4. The data source controls perform any updates. If a row is being updated, the Updating and Updated events fire. If a row is being inserted, the Inserting and Inserted events fire. If a row is being deleted, the Deleting and Deleted events fire.
    5. The Page.PreRender event fires.
    6. The data source controls perform any queries and insert the retrieved data in the linked controls. The Selecting and Selected events fire at this point.
    7. The page is rendered and disposed.
  • Custom Sorting Paging for GridView

    ObjectDataSource can do sorting paging without writing code in the aspx. The idea of using object data source is to move the code out of page.

  • Reading Binary Data Efficiently

    protected void Page_Load(object sender, System.EventArgs e)
    {
      string connectionString =
      WebConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
      SqlConnection con = new SqlConnection(connectionString);
      string SQL = "SELECT logo FROM pub_info WHERE pub_id='1389'";
      SqlCommand cmd = new SqlCommand(SQL, con);
      try
      {
        con.Open();
        SqlDataReader r =
                cmd.ExecuteReader(CommandBehavior.SequentialAccess);
        if (r.Read())
        {
          int bufferSize = 100; // Size of the buffer.
          byte[] bytes = new byte[bufferSize]; // The buffer of data.
          long bytesRead; // The number of bytes read.
          long readFrom = 0; // The starting index
          // Read the field 100 bytes at a time.
          do
          {
                bytesRead = r.GetBytes(0, readFrom, bytes, 0, bufferSize);
                Response.BinaryWrite(bytes);
                readFrom += bufferSize;
           } while (bytesRead == bufferSize);
        }
        r.Close();
    }
    finally
    {
       con.Close();
    }
    }