Ask a Question related to ASP.NET, Design and Development.
-
Simon #1
Datagrid sorting
I have read most messages in regard with this topic, and have tried
every measure suggested. I'm still haveing problem to get it to work.
Basically, the page just reloaded as before when I clicked on the
header link.
Here is the code :
************************************************** **********************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim lastSortOrder As String
Dim lastSortColumn As String
daStaffList.Fill(dsStaffList)
If Not IsPostBack Then
ViewState("LastSortOrder") = "ASC"
ViewState("LastSortColumn") = "LastName"
dvStaffList.Sort = "LastName" & " " & " ASC"
daStaffList.Fill(dsStaffList)
dgStaffList.DataBind()
End If
End Sub
Private Sub dgStaffList_SortCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dgStaffList.SortCommand
Dim newSortColumn = e.SortExpression.ToString()
Dim newSortOrder = "ASC" 'Default value
Dim lastSortColumn = ViewState("LastSortColumn")
Dim lastSortOrder = ViewState("LastSortOrder")
If (newSortColumn.Equals(lastSortColumn) And
lastSortOrder.Equals("ASC")) Then
newSortOrder = "DESC"
End If
ViewState("LastSortOrder") = newSortOrder
ViewState("LastSortColumn") = newSortColumn
dvStaffList.Sort = newSortColumn & " " & newSortOrder
daStaffList.Fill(dsStaffList)
dgStaffList.DataBind()
End Sub
************************************************** ****************************
Any help is appreciated
Simon
Simon Guest
-
Sorting in the DataGrid
It's like this: a column in a DataGrid(u know, the component) receives several numbers from an XML,one for each cell, numbers from 0 to 11. Each nr... -
DataGrid Not Sorting
My web datagrid isn't sorting at all. I have it wired up to a handler, and I know the handler is working (being called), but no sorting. The page... -
sorting a datagrid
In asp.net I have created a datagrid which it data source is determined at runtime. How can add the auto sort functionality to this datagrid? In... -
Sorting in a DataGrid with no headings
I have got a scrollable datagrid within a Div tag and a fixed header created using an HTML table. I would like to be able to sort the datagrid by... -
sorting and datagrid and underline
how to eliminate underline from sorting headers on a datagrid. I modified <A> in the style sheet. Is there any other way to accomplish this in... -
Blaise Pascal Tine #2
RE: Datagrid sorting
Hi Simon,
Could you verify that you have the following methods registered under
InitializeComponent(); ?
this.dgStaffList.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.dgStaffList_S
ortCommand);
Thanks,
Blaise Pascal Tine (MSFT)
--------------------13:59:33 GMT)>From: [email]wangs@arts.endow.gov[/email] (Simon)
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Subject: Datagrid sorting
>Date: 27 Jun 2003 06:59:33 -0700
>Organization: [url]http://groups.google.com/[/url]
>Lines: 50
>Message-ID: <efbfcd95.0306270559.4919dd9d@posting.google.com >
>NNTP-Posting-Host: 63.169.191.3
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1056722373 18471 127.0.0.1 (27 Jun 2003cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin>X-Complaints-To: [email]groups-abuse@google.com[/email]
>NNTP-Posting-Date: 27 Jun 2003 13:59:33 GMT
>Path:
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-01!sn-
xit-09!supernews.com!postnews1.google.com!not-for-mail***>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:155429
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>
>I have read most messages in regard with this topic, and have tried
>every measure suggested. I'm still haveing problem to get it to work.
>Basically, the page just reloaded as before when I clicked on the
>header link.
>Here is the code :
>************************************************* ***********************
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> Dim lastSortOrder As String
> Dim lastSortColumn As String
>
> daStaffList.Fill(dsStaffList)
>
> If Not IsPostBack Then
> ViewState("LastSortOrder") = "ASC"
> ViewState("LastSortColumn") = "LastName"
> dvStaffList.Sort = "LastName" & " " & " ASC"
> daStaffList.Fill(dsStaffList)
> dgStaffList.DataBind()
> End If
> End Sub
>
> Private Sub dgStaffList_SortCommand(ByVal source As Object, ByVal
>e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
>dgStaffList.SortCommand
> Dim newSortColumn = e.SortExpression.ToString()
> Dim newSortOrder = "ASC" 'Default value
> Dim lastSortColumn = ViewState("LastSortColumn")
> Dim lastSortOrder = ViewState("LastSortOrder")
>
>
> If (newSortColumn.Equals(lastSortColumn) And
>lastSortOrder.Equals("ASC")) Then
> newSortOrder = "DESC"
> End If
>
> ViewState("LastSortOrder") = newSortOrder
> ViewState("LastSortColumn") = newSortColumn
>
> dvStaffList.Sort = newSortColumn & " " & newSortOrder
> daStaffList.Fill(dsStaffList)
> dgStaffList.DataBind()
>
> End Sub
>************************************************* **************************>
>Any help is appreciated
>
>Simon
>Blaise Pascal Tine Guest
-
Simon Wang #3
RE: Datagrid sorting
No, I don't have that method registered.
How would I do that ? and where this code goes?
Thanks
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Simon Wang Guest
-
Yama #4
Datagrid Sorting
Hi,
When trying to dynamically add the header column name in my datagrid I lose
the sorting abilities.
private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (e.Item.ItemType == ListItemType.Header )
{
e.Item.Cells[2].Text = "Employee"
e.Item.Cells[3].Text = "Company Name"
}
}
How can I give it back the sorting ability?
Thanks,
Yama
Yama Guest
-
Jos #5
Re: Datagrid Sorting
Yama wrote:
Try this to change the header text:> Hi,
>
> When trying to dynamically add the header column name in my datagrid
> I lose the sorting abilities.
>
> private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
>
> {
>
> ListItemType itemType = e.Item.ItemType;
>
> if (e.Item.ItemType == ListItemType.Header )
>
> {
>
> e.Item.Cells[2].Text = "Employee"
>
> e.Item.Cells[3].Text = "Company Name"
>
> }
>
> }
>
> How can I give it back the sorting ability?
grd.Columns[2].HeaderText = "Employee";
grd.Columns[3].HeaderText = "Company Name";
--
Jos
Jos Guest
-
Yama #6
Re: Datagrid Sorting
Hello Jos,
You da man! Thanks that worked.
Yama
"Jos" <josnospambranders@fastmail.fm> wrote in message
news:ezxRFcQgEHA.636@TK2MSFTNGP12.phx.gbl...> Yama wrote:>> > Hi,
> >
> > When trying to dynamically add the header column name in my datagrid
> > I lose the sorting abilities.
> >
> > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
> >
> > {
> >
> > ListItemType itemType = e.Item.ItemType;
> >
> > if (e.Item.ItemType == ListItemType.Header )
> >
> > {
> >
> > e.Item.Cells[2].Text = "Employee"
> >
> > e.Item.Cells[3].Text = "Company Name"
> >
> > }
> >
> > }
> >
> > How can I give it back the sorting ability?
> Try this to change the header text:
>
> grd.Columns[2].HeaderText = "Employee";
> grd.Columns[3].HeaderText = "Company Name";
>
> --
>
> Jos
>
>
Yama Guest
-
Yama #7
Re: Datagrid Sorting
Jos,
Do you happen to know also how I could change the header text of an header
template:
<Columns>
<asp:TemplateColumn HeaderText="Select">
<HeaderTemplate>
<asp:checkbox id="chkDeleteAll"
onclick="javascript:SelectAllCheckboxes(this);" runat="server"
TextAlign="Left" Text="Select All" ToolTip="Select/Deselect All"
AutoPostBack="false"></asp:checkbox>
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ITEMTEMPLATE>
<asp:CheckBox id="chkDelete"
onclick="javascript:HighlightRow(this);" runat="server"
AutoPostBack="false"></asp:CheckBox>
</ITEMTEMPLATE>
</asp:TemplateColumn>
</Columns>
How can I change the Text="Select All" dynamically? I am using the resource
file to globalize my web apps.
Thanks,
Yama
"Jos" <josnospambranders@fastmail.fm> wrote in message
news:ezxRFcQgEHA.636@TK2MSFTNGP12.phx.gbl...> Yama wrote:>> > Hi,
> >
> > When trying to dynamically add the header column name in my datagrid
> > I lose the sorting abilities.
> >
> > private void grd_ItemDataBound(object sender, DataGridItemEventArgs e)
> >
> > {
> >
> > ListItemType itemType = e.Item.ItemType;
> >
> > if (e.Item.ItemType == ListItemType.Header )
> >
> > {
> >
> > e.Item.Cells[2].Text = "Employee"
> >
> > e.Item.Cells[3].Text = "Company Name"
> >
> > }
> >
> > }
> >
> > How can I give it back the sorting ability?
> Try this to change the header text:
>
> grd.Columns[2].HeaderText = "Employee";
> grd.Columns[3].HeaderText = "Company Name";
>
> --
>
> Jos
>
>
Yama Guest
-
Jos #8
Re: Datagrid Sorting
Yama wrote:
For this, you can use the ItemDataBound event handler.> Jos,
>
> Do you happen to know also how I could change the header text of an
> header template:
>
> <Columns>
> <asp:TemplateColumn HeaderText="Select">
> <HeaderTemplate>
> <asp:checkbox id="chkDeleteAll"
> onclick="javascript:SelectAllCheckboxes(this);" runat="server"
> TextAlign="Left" Text="Select All"
> ToolTip="Select/Deselect All" AutoPostBack="false"></asp:checkbox>
> </HeaderTemplate>
> <ItemStyle HorizontalAlign="Center"></ItemStyle>
> <ITEMTEMPLATE>
> <asp:CheckBox id="chkDelete"
> onclick="javascript:HighlightRow(this);" runat="server"
> AutoPostBack="false"></asp:CheckBox>
> </ITEMTEMPLATE>
> </asp:TemplateColumn>
> </Columns>
>
> How can I change the Text="Select All" dynamically? I am using the
> resource file to globalize my web apps.
Try:
(CheckBox)e.Item.FindControl("chkDeleteAll").Text= "new text";
--
Jos
Jos Guest
-
Yama #9
Re: Datagrid Sorting
Hi Jos,
the Text property doesn't exist... Any way to grab it and set it in another
context?
I tried the following in the Item DataBound:
CheckBox chk = (CheckBox)e.Item.FindControl("chkDeleteAll");
chk.Text = "New Test";
But I got an error that the object wasn't referenced...
Any suggestions?
Yama
"Jos" <josnospambranders@fastmail.fm> wrote in message
news:Ozqe8IWgEHA.380@TK2MSFTNGP10.phx.gbl...> Yama wrote:>> > Jos,
> >
> > Do you happen to know also how I could change the header text of an
> > header template:
> >
> > <Columns>
> > <asp:TemplateColumn HeaderText="Select">
> > <HeaderTemplate>
> > <asp:checkbox id="chkDeleteAll"
> > onclick="javascript:SelectAllCheckboxes(this);" runat="server"
> > TextAlign="Left" Text="Select All"
> > ToolTip="Select/Deselect All" AutoPostBack="false"></asp:checkbox>
> > </HeaderTemplate>
> > <ItemStyle HorizontalAlign="Center"></ItemStyle>
> > <ITEMTEMPLATE>
> > <asp:CheckBox id="chkDelete"
> > onclick="javascript:HighlightRow(this);" runat="server"
> > AutoPostBack="false"></asp:CheckBox>
> > </ITEMTEMPLATE>
> > </asp:TemplateColumn>
> > </Columns>
> >
> > How can I change the Text="Select All" dynamically? I am using the
> > resource file to globalize my web apps.
> For this, you can use the ItemDataBound event handler.
>
> Try:
> (CheckBox)e.Item.FindControl("chkDeleteAll").Text= "new text";
>
> --
>
> Jos
>
>
Yama Guest
-
Jos #10
Re: Datagrid Sorting
Yama wrote:
You're still using the condition:> Hi Jos,
>
> the Text property doesn't exist... Any way to grab it and set it in
> another context?
>
> I tried the following in the Item DataBound:
> CheckBox chk = (CheckBox)e.Item.FindControl("chkDeleteAll");
> chk.Text = "New Test";
>
> But I got an error that the object wasn't referenced...
if (e.Item.ItemType == ListItemType.Header )
aren't you?
--
Jos
Jos Guest
-
hakanh #11
Datagrid Sorting
hi everyone. How do i sort my data grid with my language when user clicks header. My language includes any special char for expamle ?, ?, ?, ?, ?, ?.
How do i make it?
hakanh Guest
-
-
srirama.83 #13
Datagrid Sorting
I have a datagrid which displays the values from the Dataset. The Dataset
values are not sorted alphabetically. So the datagrid initially displays the
values in an unsorted manner. Only when I click on the header of the datagrid
the values are displayed in assorted manner. I want the datagrid to display the
values in alphabetical order when it is loaded with the values. Can this be
done ?
If so anyone please let me know how to do that .
srirama.83 Guest
-
srirama.83 #14
Datagrid Sorting
I have a datagrid which displays the values from the Dataset. The Dataset
values are not sorted alphabetically. So the datagrid initially displays the
values in an unsorted manner. Only when I click on the header of the datagrid
the values are displayed in assorted manner. I want the datagrid to display the
values in alphabetical order when it is loaded with the values. Can this be
done ?
If so, anyone please let me know how to do that .
srirama.83 Guest
-
srirama.83 #15
Datagrid Sorting
I have a datagrid which displays the values from the Dataset. The Dataset
values are not sorted alphabetically. So the datagrid initially displays the
values in an unsorted manner. Only when I click on the header of the datagrid
the values are displayed in assorted manner. I want the datagrid to display the
values in alphabetical order when it is loaded with the values. Can this be
done ?
If so, anyone please let me know how to do that .
srirama.83 Guest
-
KLee #16
RE: Datagrid Sorting
If you are loading the data into the grid from a database, put an order by in your select with the order you want the grid loaded with.
ie. Select * from table
where ...(optional)
order by column1, column2 etc
From [url]http://www.developmentnow.com/g/70_2006_12_0_0_867047/Datagrid-Sorting.ht[/url]
Posted via DevelopmentNow.com Group
[url]http://www.developmentnow.com[/url]
KLee Guest
-
Scott Johnson #17
Re: Datagrid Sorting
sort the dataset prior to loading it into the datagrid.
Check the help files for dataset.addSort() and dataset.userSort()
Basically you will use the dataset.addSort()
dataset.addSort(name,field);
name = name you want to call this sort
filed = the field you want to sort on.
Then you call the dataset.useSort()
dataset.useSort(name)
name = what you called the sort in addSort.
Now your dataset is sorted.
srirama.83 wrote:> I have a datagrid which displays the values from the Dataset. The Dataset
> values are not sorted alphabetically. So the datagrid initially displays the
> values in an unsorted manner. Only when I click on the header of the datagrid
> the values are displayed in assorted manner. I want the datagrid to display the
> values in alphabetical order when it is loaded with the values. Can this be
> done ?
> If so anyone please let me know how to do that .
>Scott Johnson Guest
-
TroyK #18
Re: Datagrid Sorting
Looks like you want to use the addSort function of the DataSet. So before you
assign the dataset to the datagrid you would run something like this.
my_ds.addSort("nameSort", ["name"], DataSetIterator.Descending);
Later
Troy
TroyK Guest
-
srirama.83 #19
Re: Datagrid Sorting
Thanks a lot,
I Used an array as the dataset for datagrid and i used the sortOn() Function of Array.
And this worked .
srirama.83 Guest



Reply With Quote

