我的部分代码:
protected void dgrates_SortCommand(object source, DataGridSortCommandEventArgs e)
{
DataTable dt = (DataTable)Session["Source"];
DataView dv = new DataView(dt);
dv.Sort = e.SortExpression;
dgrates.DataSource = dv;
dgrates.DataBind();
}<asp:DataGrid id="dgrates" runat="server" Width="100%" BorderColor="#E7E7FF" AutoGenerateColumns="False"
AllowPaging="True" Height="100%" BackColor="White" OnSortCommand="dgrates_SortCommand">
<SelectedItemStyle Font-Names="Arial" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<EditItemStyle Font-Names="Arial"></EditItemStyle>
<AlternatingItemStyle Font-Names="Arial" CssClass="tr2" BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle Font-Names="Arial" Height="20px" ForeColor="Black" BackColor="#E2EDF9"></ItemStyle>
<HeaderStyle Wrap="False" Height="20px" BackColor="#3E76AE" Font-Bold="true" ForeColor="white"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="COUNTRYCODE" HeaderText="Country Code" ItemStyle-Width="15%" HeaderStyle-HorizontalAlign="Left" SortExpression="COUNTRYCODE"></asp:BoundColumn>
<asp:BoundColumn DataField="COUNTRYNAME" HeaderText="Country Name" HeaderStyle-HorizontalAlign="left" SortExpression="COUNTRYNAME"></asp:BoundColumn>
<asp:BoundColumn DataField="TIMECATEGORYNAME" HeaderText="Timecategory Name" ItemStyle-Width="20%" HeaderStyle-HorizontalAlign="Left"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRENCY" HeaderText="Currency" ItemStyle-Width="10%" HeaderStyle-HorizontalAlign="Left" ></asp:BoundColumn>
<asp:BoundColumn DataField="TARIFF" HeaderText="Tariff" ItemStyle-Width="10%" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ></asp:BoundColumn>
<asp:BoundColumn DataField="SETUP" HeaderText="Setup" ItemStyle-Width="10%" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ></asp:BoundColumn>
</Columns>
<PagerStyle Visible ="false" />
</asp:DataGrid>多谢!
protected void dgrates_SortCommand(object source, DataGridSortCommandEventArgs e)
{
DataTable dt = (DataTable)Session["Source"];
DataView dv = new DataView(dt);
dv.Sort = e.SortExpression;
dgrates.DataSource = dv;
dgrates.DataBind();
}<asp:DataGrid id="dgrates" runat="server" Width="100%" BorderColor="#E7E7FF" AutoGenerateColumns="False"
AllowPaging="True" Height="100%" BackColor="White" OnSortCommand="dgrates_SortCommand">
<SelectedItemStyle Font-Names="Arial" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<EditItemStyle Font-Names="Arial"></EditItemStyle>
<AlternatingItemStyle Font-Names="Arial" CssClass="tr2" BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle Font-Names="Arial" Height="20px" ForeColor="Black" BackColor="#E2EDF9"></ItemStyle>
<HeaderStyle Wrap="False" Height="20px" BackColor="#3E76AE" Font-Bold="true" ForeColor="white"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="COUNTRYCODE" HeaderText="Country Code" ItemStyle-Width="15%" HeaderStyle-HorizontalAlign="Left" SortExpression="COUNTRYCODE"></asp:BoundColumn>
<asp:BoundColumn DataField="COUNTRYNAME" HeaderText="Country Name" HeaderStyle-HorizontalAlign="left" SortExpression="COUNTRYNAME"></asp:BoundColumn>
<asp:BoundColumn DataField="TIMECATEGORYNAME" HeaderText="Timecategory Name" ItemStyle-Width="20%" HeaderStyle-HorizontalAlign="Left"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRENCY" HeaderText="Currency" ItemStyle-Width="10%" HeaderStyle-HorizontalAlign="Left" ></asp:BoundColumn>
<asp:BoundColumn DataField="TARIFF" HeaderText="Tariff" ItemStyle-Width="10%" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ></asp:BoundColumn>
<asp:BoundColumn DataField="SETUP" HeaderText="Setup" ItemStyle-Width="10%" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" ></asp:BoundColumn>
</Columns>
<PagerStyle Visible ="false" />
</asp:DataGrid>多谢!
哎
我自己搞定了