Datagrid Sorting

G

Guest

I have created a datagrid in my aspx with the 'AllowSorting' property to true.

When clicking on the column header, the page refreshes. However the sorting
is not done. Am I missing anything?

I populate the data if !postback.
 
E

Elton Wang

Hi there,

Do you implement sorting codes in DataGrid_SortCommand
event?

Elton Wang
(e-mail address removed)
-----Original Message-----
I have created a datagrid in my aspx with
the 'AllowSorting' property to true.
 
G

Guest

Yes. In fact, I made the sort through the sort event. However when I changed
the column label via the column create event, the columns were become
non-sortable.
 
E

Elton Wang

What do you mean the columns become non-sortable,
DataGrid_SortCommand can't be fired or other? Could you
give more detailed in?

Elton Wang
(e-mail address removed)
 
G

Guest

Yes.

The Data is populated in the ground (databound) on the page_load event.
Sorting is done in the SortCommand event. The custom labels are defined in
the ItemCreated event. In fact there were 5 colums to be displayed. Out of
which, I made 2 columns custom headers. These 2 columns display the text in a
non-underlined fashion so that I cannot click on it for sorting at runtime.

How can make these 2 columns again be sortable?
 
G

Guest

Yes I did. In fact the following are the event code I use.

private void DataGrid_Inspection_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataView dvInspection = new DataView();
dvInspection.Table = (DataTable)Cache["Inspection"];
dvInspection.Sort = e.SortExpression;
DataGrid_Inspection.DataSource = dvInspection;
DataGrid_Inspection.DataBind();
}



private void DataGrid_Inspection_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}
}
 
E

Elton Wang

If you really have some special reason to change Column
header, Instead of using
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}

to use
DataGrid_Inspection.Columns[0].HeaderText = "Structure";
DataGrid_Inspection.Columns[1].HeaderText = "Area";

Elton Wang
(e-mail address removed)

-----Original Message-----
Yes I did. In fact the following are the event code I use.

private void DataGrid_Inspection_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataView dvInspection = new DataView();
dvInspection.Table = (DataTable)Cache["Inspection"];
dvInspection.Sort = e.SortExpression;
DataGrid_Inspection.DataSource = dvInspection;
DataGrid_Inspection.DataBind();
}



private void DataGrid_Inspection_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}
}


Elton Wang said:
Do you assign SortExpression for these two columns?

Elton Wang be
displayed. Out of columns
display the text in a for
sorting at runtime.
.
 
G

Guest

Yes, I have a reason for doing so.

At design-time, I cannot create columns because when the data is populated,
that column appears in the page with no data, and the new fields are added to
the right side of it.

However, when I remove the columns at design time, I cannot use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
because the compiler says that the index is out or range (because no columns
exist).

In fact, I use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
after binding the data. Still it is giving an error saying that the column
is undefined.


Elton Wang said:
If you really have some special reason to change Column
header, Instead of using
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}

to use
DataGrid_Inspection.Columns[0].HeaderText = "Structure";
DataGrid_Inspection.Columns[1].HeaderText = "Area";

Elton Wang
(e-mail address removed)

-----Original Message-----
Yes I did. In fact the following are the event code I use.

private void DataGrid_Inspection_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataView dvInspection = new DataView();
dvInspection.Table = (DataTable)Cache["Inspection"];
dvInspection.Sort = e.SortExpression;
DataGrid_Inspection.DataSource = dvInspection;
DataGrid_Inspection.DataBind();
}



private void DataGrid_Inspection_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}
}


Elton Wang said:
Do you assign SortExpression for these two columns?

Elton Wang
-----Original Message-----
Yes.

The Data is populated in the ground (databound) on the
page_load event.
Sorting is done in the SortCommand event. The custom
labels are defined in
the ItemCreated event. In fact there were 5 colums to be
displayed. Out of
which, I made 2 columns custom headers. These 2 columns
display the text in a
non-underlined fashion so that I cannot click on it for
sorting at runtime.

How can make these 2 columns again be sortable?



:

What do you mean the columns become non-sortable,
DataGrid_SortCommand can't be fired or other? Could you
give more detailed in?

Elton Wang
(e-mail address removed)


-----Original Message-----
Yes. In fact, I made the sort through the sort event.
However when I changed
the column label via the column create event, the
columns
were become
non-sortable.

:

Hi there,

Do you implement sorting codes in
DataGrid_SortCommand
event?

Elton Wang
(e-mail address removed)

-----Original Message-----
I have created a datagrid in my aspx with
the 'AllowSorting' property to true.

When clicking on the column header, the page
refreshes.
However the sorting
is not done. Am I missing anything?

I populate the data if !postback.

.


.


.
.
 
E

Elton Wang

It looks like very complicated case.

Since you can't assign column's HeaderText, how do you
assign column's SortExpression? Without SortExpression,
the column is non-sortable.

I was just wondering before data was pulled out, you don't
know its structure, do you? Or it changes from time to
time.


-----Original Message-----
Yes, I have a reason for doing so.

At design-time, I cannot create columns because when the data is populated,
that column appears in the page with no data, and the new fields are added to
the right side of it.

However, when I remove the columns at design time, I cannot use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
because the compiler says that the index is out or range (because no columns
exist).

In fact, I use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
after binding the data. Still it is giving an error saying that the column
is undefined.


Elton Wang said:
If you really have some special reason to change Column
header, Instead of using
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}

to use
DataGrid_Inspection.Columns[0].HeaderText = "Structure";
DataGrid_Inspection.Columns[1].HeaderText = "Area";

Elton Wang
(e-mail address removed)

-----Original Message-----
Yes I did. In fact the following are the event code I use.

private void DataGrid_Inspection_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataView dvInspection = new DataView();
dvInspection.Table = (DataTable)Cache["Inspection"];
dvInspection.Sort = e.SortExpression;
DataGrid_Inspection.DataSource = dvInspection;
DataGrid_Inspection.DataBind();
}



private void DataGrid_Inspection_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}
}


:

Do you assign SortExpression for these two columns?

Elton Wang
-----Original Message-----
Yes.

The Data is populated in the ground (databound) on the
page_load event.
Sorting is done in the SortCommand event. The custom
labels are defined in
the ItemCreated event. In fact there were 5 colums
to
be
displayed. Out of
which, I made 2 columns custom headers. These 2 columns
display the text in a
non-underlined fashion so that I cannot click on it for
sorting at runtime.

How can make these 2 columns again be sortable?



:

What do you mean the columns become non-sortable,
DataGrid_SortCommand can't be fired or other?
Could
you
give more detailed in?

Elton Wang
(e-mail address removed)


-----Original Message-----
Yes. In fact, I made the sort through the sort event.
However when I changed
the column label via the column create event, the
columns
were become
non-sortable.

:

Hi there,

Do you implement sorting codes in
DataGrid_SortCommand
event?

Elton Wang
(e-mail address removed)

-----Original Message-----
I have created a datagrid in my aspx with
the 'AllowSorting' property to true.

When clicking on the column header, the page
refreshes.
However the sorting
is not done. Am I missing anything?

I populate the data if !postback.

.


.


.


.
.
 
G

Guest

I cannot hardcode the statements.

My sql string will be different; my columns will be different.

All what I'm looking is that I want some data displayed from a table with
custom headers and being able to sort on all of those columns.

Elton Wang said:
It looks like very complicated case.

Since you can't assign column's HeaderText, how do you
assign column's SortExpression? Without SortExpression,
the column is non-sortable.

I was just wondering before data was pulled out, you don't
know its structure, do you? Or it changes from time to
time.


-----Original Message-----
Yes, I have a reason for doing so.

At design-time, I cannot create columns because when the data is populated,
that column appears in the page with no data, and the new fields are added to
the right side of it.

However, when I remove the columns at design time, I cannot use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
because the compiler says that the index is out or range (because no columns
exist).

In fact, I use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
after binding the data. Still it is giving an error saying that the column
is undefined.


Elton Wang said:
If you really have some special reason to change Column
header, Instead of using
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}

to use
DataGrid_Inspection.Columns[0].HeaderText = "Structure";
DataGrid_Inspection.Columns[1].HeaderText = "Area";

Elton Wang
(e-mail address removed)


-----Original Message-----
Yes I did. In fact the following are the event code I use.

private void DataGrid_Inspection_SortCommand(object
source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataView dvInspection = new DataView();
dvInspection.Table = (DataTable)Cache["Inspection"];
dvInspection.Sort = e.SortExpression;
DataGrid_Inspection.DataSource = dvInspection;
DataGrid_Inspection.DataBind();
}



private void DataGrid_Inspection_ItemCreated(object
sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}
}


:

Do you assign SortExpression for these two columns?

Elton Wang
-----Original Message-----
Yes.

The Data is populated in the ground (databound) on the
page_load event.
Sorting is done in the SortCommand event. The custom
labels are defined in
the ItemCreated event. In fact there were 5 colums to
be
displayed. Out of
which, I made 2 columns custom headers. These 2
columns
display the text in a
non-underlined fashion so that I cannot click on it
for
sorting at runtime.

How can make these 2 columns again be sortable?



:

What do you mean the columns become non-sortable,
DataGrid_SortCommand can't be fired or other? Could
you
give more detailed in?

Elton Wang
(e-mail address removed)


-----Original Message-----
Yes. In fact, I made the sort through the sort
event.
However when I changed
the column label via the column create event, the
columns
were become
non-sortable.

:

Hi there,

Do you implement sorting codes in
DataGrid_SortCommand
event?

Elton Wang
(e-mail address removed)

-----Original Message-----
I have created a datagrid in my aspx with
the 'AllowSorting' property to true.

When clicking on the column header, the page
refreshes.
However the sorting
is not done. Am I missing anything?

I populate the data if !postback.

.


.


.


.
.
 
G

Guest

As I think there might be some way to do it.

You may try that after pulling data but before binding
data source to datagrid.

For example, you got data in a datatable, tbl.

BoundColumn boundCol;
foreach (DataColumn col in tbl.Columns){
boundCol = new BoundColumn();
boundCol.HeaderText = col.ColumnName
boundCol.SortExpression = col.ColumnName
DataGrid_Inspection.Columns.Add(boundCol);
}

Then you can bind data.

Hope it helps,

Elton Wang
(e-mail address removed)


-----Original Message-----
I cannot hardcode the statements.

My sql string will be different; my columns will be different.

All what I'm looking is that I want some data displayed from a table with
custom headers and being able to sort on all of those columns.

Elton Wang said:
It looks like very complicated case.

Since you can't assign column's HeaderText, how do you
assign column's SortExpression? Without SortExpression,
the column is non-sortable.

I was just wondering before data was pulled out, you don't
know its structure, do you? Or it changes from time to
time.


-----Original Message-----
Yes, I have a reason for doing so.

At design-time, I cannot create columns because when
the
data is populated,
that column appears in the page with no data, and the
new
fields are added to
the right side of it.

However, when I remove the columns at design time, I cannot use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
because the compiler says that the index is out or
range
(because no columns
exist).

In fact, I use:
DataGrid_Inspection.Columns[0].HeaderText = "Structure"
after binding the data. Still it is giving an error saying that the column
is undefined.


:

If you really have some special reason to change Column
header, Instead of using
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}

to use
DataGrid_Inspection.Columns[0].HeaderText = "Structure";
DataGrid_Inspection.Columns[1].HeaderText = "Area";

Elton Wang
(e-mail address removed)


-----Original Message-----
Yes I did. In fact the following are the event code
I
use.
private void DataGrid_Inspection_SortCommand(object
source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs
e)
{
DataView dvInspection = new DataView();
dvInspection.Table = (DataTable)Cache["Inspection"];
dvInspection.Sort = e.SortExpression;
DataGrid_Inspection.DataSource = dvInspection;
DataGrid_Inspection.DataBind();
}



private void DataGrid_Inspection_ItemCreated(object
sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[0].Text = "Structure";
e.Item.Cells[1].Text = "Area";
}
}


:

Do you assign SortExpression for these two columns?

Elton Wang
-----Original Message-----
Yes.

The Data is populated in the ground (databound)
on
the
page_load event.
Sorting is done in the SortCommand event. The custom
labels are defined in
the ItemCreated event. In fact there were 5
colums
to
be
displayed. Out of
which, I made 2 columns custom headers. These 2
columns
display the text in a
non-underlined fashion so that I cannot click on it
for
sorting at runtime.

How can make these 2 columns again be sortable?



:

What do you mean the columns become non- sortable,
DataGrid_SortCommand can't be fired or other? Could
you
give more detailed in?

Elton Wang
(e-mail address removed)


-----Original Message-----
Yes. In fact, I made the sort through the sort
event.
However when I changed
the column label via the column create event, the
columns
were become
non-sortable.

:

Hi there,

Do you implement sorting codes in
DataGrid_SortCommand
event?

Elton Wang
(e-mail address removed)

-----Original Message-----
I have created a datagrid in my aspx with
the 'AllowSorting' property to true.

When clicking on the column header, the page
refreshes.
However the sorting
is not done. Am I missing anything?

I populate the data if !postback.

.


.


.


.


.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top