views:

69

answers:

1

I am using autogeneratecolumns ="false" and using some template fields.

It works when I use:

tempColumnNew = Me.DataGrid.Columns(oldColIndex)
tempColumnOld = Me.DataGrid.Columns(newColIndex)

Me.DataGrid.Columns.RemoveAt(oldColIndex)
Me.DataGrid.Columns.RemoveAt(newColIndex)

Me.DataGrid.Columns.AddAt(oldColIndex, tempColumnOld)
Me.DataGrid.Columns.AddAt(newColIndex, tempColumnNew)

But it doesnt remember the added columns on postback, so I have to add them for every postback.

Is there a better way to implement it?

A: 

Are you using IsPostBack on the Page_Load event?

If Not IsPostBack Then
  tempColumnNew = Me.DataGrid.Columns(oldColIndex)
  tempColumnOld = Me.DataGrid.Columns(newColIndex)

  Me.DataGrid.Columns.RemoveAt(oldColIndex)
  Me.DataGrid.Columns.RemoveAt(newColIndex)

  Me.DataGrid.Columns.AddAt(oldColIndex, tempColumnOld)
  Me.DataGrid.Columns.AddAt(newColIndex, tempColumnNew)
End If
fuz3d
Thanks for your reply....I am using ispostback, but this code is in the Binddata method.....which is called to bind the data to the datagrid.......
Som
bind data is called even if its not a post back and also on post back...
Som