T
tshad
I am trying to allow my clients to specify the order that columns show in a
datagrid.
If I have a Datagrid like so:
<asp
ataGrid
Visible=true
AllowSorting="false"
AutoGenerateColumns="false"
CellPadding="0"
CellSpacing="0"
ID="DataGrid2"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="0"
BorderColor="#999999"
Width="701px"
style="padding-right:5px">
<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="190px" HeaderStyle-Width="190px"
headertext="Job Title" ItemStyle-VerticalAlign="Top"
runat="server">
<ItemTemplate>
<asp:HyperLink ID="JobTitle"
NavigateURL='<%# "displayPositionNew.aspx?PositionID=" &
Container.DataItem("PositionID") %>'
Text='<%# Container.DataItem("JobTitle")%>'
OnPreRender="FixHyperLink"
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn ItemStyle-Width="150" DataField="Company"
HeaderText="Company"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="Company"/>
<asp:BoundColumn ItemStyle-Width="110" DataField="Location"
HeaderText="Location"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="Location"/>
</columns>
</asp
ataGrid>
I have 3 columns: JobTitle, Company and Location - in that order.
But one client may want the client to be Company, Location, JobTitle and
another may want it to be Location, JobTitle,Company.
Is there a way to change the order of the columns as they are displayed?
I mentioned in another post that I change the size of the DataGrid and hide
columns in my PreRender event, like so:
DataGrid1.Width = new Unit("551px")
for each col as DataGridColumn in DataGrid1.Columns
if col.HeaderText = "Company" orElse col.HeaderText = "Posted" then
col.Visible = false
end if
next
Can I do something like this to also change the order in the table?
Thanks,
Tom
datagrid.
If I have a Datagrid like so:
<asp
Visible=true
AllowSorting="false"
AutoGenerateColumns="false"
CellPadding="0"
CellSpacing="0"
ID="DataGrid2"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="0"
BorderColor="#999999"
Width="701px"
style="padding-right:5px">
<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="190px" HeaderStyle-Width="190px"
headertext="Job Title" ItemStyle-VerticalAlign="Top"
runat="server">
<ItemTemplate>
<asp:HyperLink ID="JobTitle"
NavigateURL='<%# "displayPositionNew.aspx?PositionID=" &
Container.DataItem("PositionID") %>'
Text='<%# Container.DataItem("JobTitle")%>'
OnPreRender="FixHyperLink"
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn ItemStyle-Width="150" DataField="Company"
HeaderText="Company"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="Company"/>
<asp:BoundColumn ItemStyle-Width="110" DataField="Location"
HeaderText="Location"
ReadOnly="true"
Visible="True"
ItemStyle-VerticalAlign="Top"
SortExpression="Location"/>
</columns>
</asp
I have 3 columns: JobTitle, Company and Location - in that order.
But one client may want the client to be Company, Location, JobTitle and
another may want it to be Location, JobTitle,Company.
Is there a way to change the order of the columns as they are displayed?
I mentioned in another post that I change the size of the DataGrid and hide
columns in my PreRender event, like so:
DataGrid1.Width = new Unit("551px")
for each col as DataGridColumn in DataGrid1.Columns
if col.HeaderText = "Company" orElse col.HeaderText = "Posted" then
col.Visible = false
end if
next
Can I do something like this to also change the order in the table?
Thanks,
Tom