2

gridview列ヘッダーは、保護されたvoid GridView1_RowDataBound(object sender、GridViewRowEventArgs e){GridView grid = sender as GridView; DataRowView tableData = e.Row.DataItem as DataRowView;

    if (e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.Cells[1].Text = System.DateTime.Now.AddMonths(-3).ToString("MMMM") ;
    }
}

この特定の列をコードビハインドから並べ替えるにはどうすればよいですか。file.asp

<asp:TemplateField ItemStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="Bottom" ItemStyle-Wrap="False">
<ItemTemplate>
<asp:Label ID="lblMonth_1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>

ありがとう。

4

1 に答える 1

1

You may not need to go to the code behind for this. What kind of database are you using?

Have you considered modifying your query to include another column?

select mydate, dateadd(m, -3, mydate) as olderdate from mytable;

Then you can just make your gridview field as:

<asp:BoundField DataField="olderdate" HeaderText="Older Date" SortExpression="olderdate" dataformatstring="{0:MMM}">
    <ItemStyle Wrap="False" />
</asp:BoundField>

And mark your gridview as AllowSorting="true".

于 2012-10-09T23:21:09.490 に答える