• 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();
    }
    }
    
  • GridView RowCommand event

            In the RowDeleting, SelectedIndexChanging, RowUpdating, RowEditing, you can retrieve row index like e.RowIndex, or e.NewSelectedIndex, e.NewEditIndex. But GridVeiwCommandEventArgs has not index attribute. So how can you get the row index in RowCommand event? It turns out that GridViewComandEventArgs has an additional e.CommandArgument, in the events above it will return the row index.
    
  • Ten Step to professional web type

            <ul>
            <li>Do not use too many fonts on one page.</li>
            <li>Do not use centered, right, or full-justified text on a web page</li>
            <li>Give your text room to breath.</li>