T
tshad
I am having a real problem getting some of these methods to work.
I am trying to do a CopyTo and I can't get it to copy into my array.
I tried:
Sub ReorderDataGrid()
Dim theArray(1) as DataGridColumn
DataGrid1.Columns.CopyTo(theArray,0)
End Sub
And I get this:
System.IndexOutOfRangeException: Index was outside the bounds of the array
The error is on the CopyTo statement.
My DataGrid looks like:
<asp:ataGrid
Visible=true
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="0"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="0"
BorderColor="#999999"
style="padding-right:5px; width:573px">
<headerstyle Font-Bold="true" />
<alternatingitemstyle CssClass="alternateRows" />
<footerstyle BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Bold="true"
/>
<pagerstyle BackColor="white" />
<columns>
<asp:TemplateColumn sortexpression="JobTitle" ItemStyle-Width="190"
HeaderStyle-Width="190"
headertext="Job Title" ItemStyle-VerticalAlign="Top"
runat="server">
<ItemTemplate>
<asp:HyperLink ID="JobTitle"
NavigateURL='<%# "displayPositionNS.aspx?PositionID=" &
Container.DataItem("PositionID") %>'
Text='<%# Container.DataItem("JobTitle")%>'
OnPreRender="FixHyperLink"
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn ItemStyle-Width="100" DataField="Location"
HeaderText="Location"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="Location"/>
<asp:BoundColumn ItemStyle-Width="40" DataField="PositionType"
HeaderText="Type"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="PositionType"/>
</columns>
</aspataGrid>
If I do:
Sub ReorderDataGrid()
Dim theArray() as DataGridColumn
DataGrid1.Columns.CopyTo(theArray,0)
End Sub
And I get this:
System.NullReferenceException: Object reference not set to an instance of an
object.
I tried running the ReorderDataGrid() from Page_Load before and after
Binding the Grid as well as in the Page_PreRender with the same results.
But this is how the examples I have found on the web have it.
What am I missing?
Thanks,
Tom
I am trying to do a CopyTo and I can't get it to copy into my array.
I tried:
Sub ReorderDataGrid()
Dim theArray(1) as DataGridColumn
DataGrid1.Columns.CopyTo(theArray,0)
End Sub
And I get this:
System.IndexOutOfRangeException: Index was outside the bounds of the array
The error is on the CopyTo statement.
My DataGrid looks like:
<asp:ataGrid
Visible=true
AllowSorting="true"
AutoGenerateColumns="false"
CellPadding="0"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="0"
BorderColor="#999999"
style="padding-right:5px; width:573px">
<headerstyle Font-Bold="true" />
<alternatingitemstyle CssClass="alternateRows" />
<footerstyle BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Bold="true"
/>
<pagerstyle BackColor="white" />
<columns>
<asp:TemplateColumn sortexpression="JobTitle" ItemStyle-Width="190"
HeaderStyle-Width="190"
headertext="Job Title" ItemStyle-VerticalAlign="Top"
runat="server">
<ItemTemplate>
<asp:HyperLink ID="JobTitle"
NavigateURL='<%# "displayPositionNS.aspx?PositionID=" &
Container.DataItem("PositionID") %>'
Text='<%# Container.DataItem("JobTitle")%>'
OnPreRender="FixHyperLink"
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn ItemStyle-Width="100" DataField="Location"
HeaderText="Location"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="Location"/>
<asp:BoundColumn ItemStyle-Width="40" DataField="PositionType"
HeaderText="Type"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="PositionType"/>
</columns>
</aspataGrid>
If I do:
Sub ReorderDataGrid()
Dim theArray() as DataGridColumn
DataGrid1.Columns.CopyTo(theArray,0)
End Sub
And I get this:
System.NullReferenceException: Object reference not set to an instance of an
object.
I tried running the ReorderDataGrid() from Page_Load before and after
Binding the Grid as well as in the Page_PreRender with the same results.
But this is how the examples I have found on the web have it.
What am I missing?
Thanks,
Tom