Dean
Dean

Reputation: 5946

Programatically changing ASP Gridview column header text breaks sorting

I have gridview bound to an Entity Data source which works no problem, however when I try to programatically change a header columns text, it appears to break the styling and will not allow sorting either, below is how I am trapping and changing the Header row column text.

Does anyone have any ideas?

Protected Sub gv1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv1.RowDataBound
        If e.Row.RowType = DataControlRowType.Header Then
            'retrieve the values from the userdeftable



            e.Row.Cells(6).Text = App.Session.Company.UserDef3


        End If
    End Sub

Upvotes: 0

Views: 11573

Answers (2)

Fandango68
Fandango68

Reputation: 4858

Use the Sorted event...

Example of how to toggle HeaderText to show the order of the data.

protected void gvCurrCheckIns_Sorted(object sender, EventArgs e)
    {
        if (gvCurrCheckIns.Columns[8].HeaderText.Contains("(DESC)"))
            gvCurrCheckIns.Columns[8].HeaderText = "Checked IN (ASC)";
        else
            gvCurrCheckIns.Columns[8].HeaderText = "Checked IN (DESC)";
    }

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460098

Use the HeaderText-property of the column.

Me.gv1.Columns(6).HeaderText = App.Session.Company.UserDef3

Upvotes: 3

Related Questions