Question regarding forcing a postback event

Discussion in 'ASP .Net Building Controls' started by Michael Horton, Jun 29, 2003.

  1. I've dynamically creating a datagrid and have the grid setup to allow
    sorting. The problem is that the event isn't getting called until after the
    table is created. How can I get it to to fire earler? I'm guessing I need to
    know how to find out what the e.sortexpression value is and call the
    procedure before calling the CreateGrid sub. I've attached the code
    CreateGrid sub below

    Public Sub CreateGrid()

    'declare a new datagrid and set properties

    Dim dgDrivers As New DataGrid()

    dgDrivers.BorderWidth = Unit.Pixel(0)

    dgDrivers.CellPadding = 5

    dgDrivers.GridLines = GridLines.None

    dgDrivers.BorderColor = System.Drawing.Color.Empty

    dgDrivers.ShowHeader = True

    dgDrivers.AutoGenerateColumns = False

    dgDrivers.SelectedItemStyle.BackColor = System.Drawing.Color.Empty

    dgDrivers.AllowSorting = True

    'add bound columns to the datagrid

    Dim datagridcol As New BoundColumn()

    datagridcol.HeaderText = "Car #"

    datagridcol.DataField = "car #"

    datagridcol.SortExpression = "Car #"

    dgDrivers.Columns.Add(datagridcol)

    datagridcol = New BoundColumn()

    datagridcol.HeaderText = "Name"

    datagridcol.DataField = "Name"

    datagridcol.SortExpression = "Name"

    dgDrivers.Columns.Add(datagridcol)

    datagridcol = New BoundColumn()

    datagridcol.HeaderText = "Status"

    datagridcol.DataField = "Status"

    'datagridcol.DataFormatString = "{0:d}"

    datagridcol.SortExpression = "Status"

    dgDrivers.Columns.Add(datagridcol)

    datagridcol = New BoundColumn()

    datagridcol.HeaderText = "Hometown"

    datagridcol.DataField = "Hometown"

    datagridcol.SortExpression = "HomeTown"

    dgDrivers.Columns.Add(datagridcol)

    'add event handlers

    AddHandler dgDrivers.SortCommand, AddressOf dgDriver_Sort

    dgDrivers.DataSource = DisplayDrivers()

    dgDrivers.DataBind()

    'add datagrid to the page

    Page.Controls(1).Controls.Add(dgDrivers)

    End Sub
     
    Michael Horton, Jun 29, 2003
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.