datagrid question

Posts   
 
    
mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 09-Nov-2004 10:16:05   

Hi,

i have an datagrid that works. the columns are autogenerated and i've added an editcommandcolumn in the aspx-file. this works.

however when i move the editcommandcolumn to the aspx.vb-file when i click on the edit, the "column" is removed.

my code is:

Private Sub AddColumnsToGrid() Dim theEdit As New EditCommandColumn theEdit.ButtonType = ButtonColumnType.LinkButton theEdit.CancelText = "Cancel" theEdit.EditText = "Edit" theEdit.UpdateText = "Update"

  theGrid.Columns.Add(theEdit)

End Sub

and in the page_load i call this procedure.

my aspx-snippet:

<aspsmile atagrid id=theGrid runat="server" OnSortCommand="SortByColumn" OnEditCommand="DataGrid_Edit" OnUpdateCommand="DataGrid_Update" OnCancelCommand="DataGrid_Cancel" OnItemCommand="DataGrid_Command" AutoGenerateColumns = "True" ShowFooter = "True" EnableViewState="True" CssClass = "datagrid" AllowSorting = "True"> <AlternatingItemStyle CssClass="datagridalternatingitem"/> <ItemStyle CssClass="datagriditem"/> <HeaderStyle CssClass="datagridheader"/> <PagerStyle CssClass="datagridpager"/> </aspsmile atagrid>

tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 18-Nov-2004 20:00:40   

mafti wrote:

Hi,

i have an datagrid that works. the columns are autogenerated and i've added an editcommandcolumn in the aspx-file. this works.

however when i move the editcommandcolumn to the aspx.vb-file when i click on the edit, the "column" is removed.

my code is:

Private Sub AddColumnsToGrid() Dim theEdit As New EditCommandColumn theEdit.ButtonType = ButtonColumnType.LinkButton theEdit.CancelText = "Cancel" theEdit.EditText = "Edit" theEdit.UpdateText = "Update"

  theGrid.Columns.Add(theEdit)

End Sub

and in the page_load i call this procedure.

my aspx-snippet:

<aspsmile atagrid id=theGrid runat="server" OnSortCommand="SortByColumn" OnEditCommand="DataGrid_Edit" OnUpdateCommand="DataGrid_Update" OnCancelCommand="DataGrid_Cancel" OnItemCommand="DataGrid_Command" AutoGenerateColumns = "True" ShowFooter = "True" EnableViewState="True" CssClass = "datagrid" AllowSorting = "True"> <AlternatingItemStyle CssClass="datagridalternatingitem"/> <ItemStyle CssClass="datagriditem"/> <HeaderStyle CssClass="datagridheader"/> <PagerStyle CssClass="datagridpager"/> </aspsmile atagrid>

Based on the code you have given the only thing I can think of is that your method AddColumnsToGrid() is inside of an if statement that tests for the IsPostBack property. This might cause it to not get displayed after a post back.