Formatting SQL*Plus Output 12 September 2005 at 00:00
Set the following values to make the output in SQL*Plus more readable:

  set recsep off
  set linesize 1000
  set newpage 0
  set pagesize 50
  column column1 format a10
  column column2 format a20
  column column3 format a30

Setting linesize sets the maximum length of a line before it wraps; setting pagesize determines how many records are written to screen before field names are repeated.

Working with ASP.NET DataGrids 20 September 2005 at 00:00

Adding images to DataGrid Headers

It is often useful to add "sorting images" to datagrid columns that can be sorted on a web page. However, there isn't an obvious way of adding these images if the HeaderText property is set for each column.

One way of doing it, is to add an image control to the appropriate header during the binding of the data.

In the following example, I have a Sort property on my Page object that returns the current sort field; a SortDirection property that returns "ASC" or "DESC" from ViewState; and my data grid is called dgRequests:

  private void dgRequests_ItemDataBound(object sender, 
   System.Web.UI.WebControls.DataGridItemEventArgs e) {
    if (e.Item.DataItem == null) {
      DataGrid dg = (DataGrid)sender;
      DataGridColumn col;
      for (int i=0; i<dg.Columns.Count; i++) {
        col = dg.Columns[i];
        if (col.SortExpression == this.Sort) {
          System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
          img.ImageUrl = ((SortDirection == "ASC") ? 
            "images/arrow_up.gif" : "images/arrow_down.gif");
          e.Item.Cells[i].Controls.Add(img);        
        }
      }
    }
  }

Changing default behaviour of paging buttons

Sometimes you need to get at paging buttons - for example I was working on a project where ViewState was banned due to the page bloat it created and a maximum allowable page size of 40k.

Turning off view state does NOT mean you have to abandon the paging that comes with the grid - all you have to do is edit the attributes of the links at run time with the ItemCreated event.

  this.gridComms.ItemCreated += new 
    System.Web.UI.WebControls.DataGridItemEventHandler(this.gridComms_ItemCreated);

......


  private void gridComms_ItemCreated(object sender, 
    System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
    if (e.Item.ItemType == ListItemType.Pager) 
    {
      TableCell pager = (TableCell) e.Item.Controls[0];
        foreach (Control c in pager.Controls) 
        {
          if (c is LinkButton) 
          {
            LinkButton btn = (LinkButton)c;
            btn.Attributes.Add("onclick", "changePage('" + btn.Text + 
              "');return false;");
          }
        }
    }
  }
Java apps : Ensuring jars exist before running your application 22 September 2005 at 00:00
If you use multiple jars with your application, it's a good idea to check that they've all loaded as the application may load, but strange errors can occur only later when the program tries to execute something on a class not in the classpath.

My solution for this is to attempt to load one class from each external jar file during my main method - and if any of the calls fails I show a JOptionPane and exit.

  import javax.swing.*;

  ..

  private static void checkJar(String className, String jarFile) {
    try {
      ClassLoader cl = ClassLoader.getSystemClassLoader();
      cl.loadClass(className);
    }
    catch (ClassNotFoundException e) {
      JOptionPane.showMessageDialog(null, "Unable to load required jar file "" + jarFile + "" - WebEdit is unable to load.", "Fatal Error", JOptionPane.ERROR_MESSAGE);
      System.exit(0);
    }
  }

  .. 

  public static void main(String[] args) {
    checkJar("com.test.SomeClass", "somejar.jar");
    MyApp myapp = new MyApp();
    ..
  }