|
 |
aspx thread: Re: DataGrid, Sorting
Message #1 by "jon cowan" <joncowan@y...> on Mon, 9 Apr 2001 20:54:55
|
|
Timothy,
I have had the same problem. I can't seem to get my event handlers to get
called when I dynamically create the bound columns. Have you had any luck?
The sorting works fine if the columns are autogenerated, but not if you
create your own columns in code.
Jon
> Hi,
> I am new to the .Net, please help me with the following problem, I have
> stucked with this problem for a few days.
> The following DataGrid is working fine in term of sortings when I click
> the column headers:
>
> <ASP:DataGrid id="DG" runat="server"
> OnSortCommand="DataSort"
> AutoGenerateColumns="False">
>
> <property name="Columns">
> <asp:BoundColumn HeaderText='A' DataField='A' SortField='A'>
> </asp:BoundColumn>
> <asp:BoundColumn HeaderText='B' DataField='B' SortField='B'>
> </asp:BoundColumn>
> <asp:BoundColumn HeaderText='C' DataField='C' SortField='C'>
> </asp:BoundColumn>
> </property>
>
> </ASP:DataGrid>
>
> But when bound the column dynamically, the gris will display when the
> pageload, but when I click the column header, it returns with a BLANK
> page. Still don't have any clue for a few days. Following is the code:
>
> <ASP:DataGrid id="DG" runat="server"
> OnSortCommand="DataSort"
> AutoGenerateColumns="False">
> </ASP:DataGrid>
>
> The DataSort function has the following code:
>
> DataTable dt = ds.Tables[0];
> foreach (DataColumn dc in dt.Columns) {
> BoundColumn bc = new BoundColumn();
> bc.HeaderText = dc.ColumnName;
> bc.DataField = dc.ColumnName;
> bc.SortField = dc.ColumnName;
>
> DG.Columns.Add (bc);
> }
>
> Am I missing any other properties that needed to be set at run time?
When
> I do the trace, the function "DataSort" has NEVER being called at all
when
> I click the column header.
>
> Any helps will be appreciated.
> Thanks in advance
>
Message #2 by "Li, Fang" <fang@c...> on Mon, 9 Apr 2001 18:04:01 -0400
|
|
The following code works for me.
If not help, Please look at:
http://msdn.microsoft.com/library/techart/datagrid.htm
they have a very good article.
Fang
<asp:datagrid id=dgResult runat="Server" MaintainState="False"
...
AutoGenerateColumns="False"
AllowSorting="true"
OnSortCommand = "OnSortCommand"
>
<property name="Columns">
<asp:boundcolumn HeaderText="Category" datafield ="Category"
SortField="Category" headerstyle-horizontalalign="Center">
<property name = "HeaderStyle" >
<asp:tableitemstyle width ="80px"/>
</property>
</asp:boundcolumn>
</property>
</asp:datagrid>
<script language="c#" runat="server">
protected void OnSortCommand(object sender, DataGridSortCommandEventArgs e)
{
string curField = e.SortField;
..
}
-----Original Message-----
From: jon cowan [mailto:joncowan@y...]
Sent: Monday, April 09, 2001 4:55 PM
To: ASP+
Subject: [aspx] Re: DataGrid, Sorting
Timothy,
I have had the same problem. I can't seem to get my event handlers to get
called when I dynamically create the bound columns. Have you had any luck?
The sorting works fine if the columns are autogenerated, but not if you
create your own columns in code.
Jon
> Hi,
> I am new to the .Net, please help me with the following problem, I have
> stucked with this problem for a few days.
> The following DataGrid is working fine in term of sortings when I click
> the column headers:
>
> <ASP:DataGrid id="DG" runat="server"
> OnSortCommand="DataSort"
> AutoGenerateColumns="False">
>
> <property name="Columns">
> <asp:BoundColumn HeaderText='A' DataField='A' SortField='A'>
> </asp:BoundColumn>
> <asp:BoundColumn HeaderText='B' DataField='B' SortField='B'>
> </asp:BoundColumn>
> <asp:BoundColumn HeaderText='C' DataField='C' SortField='C'>
> </asp:BoundColumn>
> </property>
>
> </ASP:DataGrid>
>
> But when bound the column dynamically, the gris will display when the
> pageload, but when I click the column header, it returns with a BLANK
> page. Still don't have any clue for a few days. Following is the code:
>
> <ASP:DataGrid id="DG" runat="server"
> OnSortCommand="DataSort"
> AutoGenerateColumns="False">
> </ASP:DataGrid>
>
> The DataSort function has the following code:
>
> DataTable dt = ds.Tables[0];
> foreach (DataColumn dc in dt.Columns) {
> BoundColumn bc = new BoundColumn();
> bc.HeaderText = dc.ColumnName;
> bc.DataField = dc.ColumnName;
> bc.SortField = dc.ColumnName;
>
> DG.Columns.Add (bc);
> }
>
> Am I missing any other properties that needed to be set at run time?
When
> I do the trace, the function "DataSort" has NEVER being called at all
when
> I click the column header.
>
> Any helps will be appreciated.
> Thanks in advance
>
|
|
 |