Вернуться   Форум программистов > Форум Программирование > Форум .NET

.NET

Технология .NET

Ответ
 
Старый 28.11.2001, 14:13   #1
Abdulla
Новичок
 
Регистрация: 21.06.2001
Сообщений: 28
Abdulla пока не определено
По умолчанию Сортировка в DataGrid

Собственно, сабж.
Долго молотил документация, но не нарыл: можно ли в DataGrid сделать сортировку по клику в Header поля, по которому надо отсортировать весь DataGrid.

Мож, кто уже встретил и победил - подскажите, плиз.

С уважением,
Руслан.
Abdulla вне форума  
Старый 13.12.2001, 19:07   #2
henry
Новичок
 
Регистрация: 13.12.2001
Сообщений: 3
henry пока не определено
По умолчанию RE: Сортировка в DataGrid

Класс :
Код
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
        public class SortingDataGrid1 : Page
        {
                protected DataGrid DataGrid1;
 
                private void Page_Load(object sender, System.EventArgs e)
                {
                        if(!Page.IsPostBack)
                        {
                                //On the first request, Bind the DataGrid
                                BindData(null);
                        }
                }
 
                private void BindData(string _sortExpression)
                {
                        //Create the DataView and cache it to improvwe performance
                        //BooksData _booksData = new BooksData();
                        BooksData _booksData = new BooksData();
                        DataView _data = _booksData.GetAllBooks();
                        
                        //If the _sortExpression has a value, sort the
                        //DataView, otherwise just bind the DataGrid
                        if(_sortExpression != null)
                        {
                                _data.Sort = _sortExpression;
                        }
                        
                        //Bind the DataGrid
                        DataGrid1.DataSource = _data;
                        DataGrid1.DataBind();
                }
                
                protected void SortCommand_OnClick(object sender, DataGridSortCommandEventArgs e)
                {
                        //When a sort link is clicked, bind the 
                        //DataGrid using the SortExpression
                        BindData(e.SortExpression);
                }
        }
 
ASP страница :
[code]
<%@ Page language='c#' Codebehind='SortingDataGrid1.aspx.cs' Inherits='DayOfDotNet.SortingDataGrid1' %>
<html>
<body style='font: x-small Verdana, Arial, sans-serif;'>
<!-- Begin Web Form -->
<form id='SortingDataGrid1' method='post' runat='server'>
<p>
<a href='/ADayOfDotNet/'>Parent Directory</a>
</p>
<!-- Begin DataGrid -->
<aspataGrid id='DataGrid1' runat='server' AutogenerateColumns='False' CellPadding='2' CellSpacing='0' Font-Names='Verdana, Arial, sans-serif' BorderColor='Black' BorderWidth='1' GridLines='Horizontal' AllowSorting='True' OnSortCommand='SortCommand_OnClick'>
<HeaderStyle Font-Bold='True' Font-Size='small' Font-Name='Arial' BackColor='Maroon' ForeColor='White' />
<ItemStyle Font-Size='x-small' />
<AlternatingItemStyle BackColor='Tan' />
<Columns>
<asp:TemplateColumn ItemStyle-VerticalAlign='Top'>
<ItemTemplate>
<img src='images/<%# DataBinder.Eval(Container.DataItem, 'ImageSrc') %>' Alt='<%# DataBinder.Eval(Container.DataItem, 'Title' ) %>'>
</ItemTemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn DataTextField='Title' DataNavigateUrlField='ISBN' DataNavigateUrlFormatString='DynamicEmbeddedDataGr id.aspx?isbn={0}' HeaderText='Title' ItemStyle-VerticalAlign='Top' SortExpression='Title' />
<asp:TemplateColumn ItemStyle-VerticalAlign='Top' HeaderText='Info (Sort by Price)' SortExpression='Price'>
<ItemTemplate>
<b>Publisher:</b> <a href='<%# DataBinder.Eval(Container.DataItem, 'PublisherURL') %>' target='_blank'>
<%# DataBinder.Eval(Container.DataItem, 'PublisherName') %>
</a>


<b>Release Date:</b>
<%# DataBinder.Eval(Container.DataItem, 'ReleaseDate', '{0:d}') %>


<b>Price:</b>
<%# DataBinder.Eval(Container.DataItem, 'Price', '{0:c}') %>


<a href='<%# DataBinder.Eva
henry вне форума  
Ads
Ответ
Опции темы

Похожие темы
Тема Автор
Помогите найти некоторые файлы по VS.Net .NET
купил VS.Net на 4х дисках. не посмотрел когда покупал, один диск поцарапан. ехать менять просто физически нет времени. помогите выложите плз след файлы со второго диска на фтп кто может(или...
mogadanez
.NET Как сделать всплывающее окно?
Имею желание сделать следующее.Кнопка - Всплывает окно с <asp:Calendar> ... Выбрал Дату - return значение в TextBox1.Text. Собственно, всё. Как сделать всплывающее окно? И как потом вернуть...
Abdulla
dotNET for middle tier components .NET
Может быть вопрос подходит под категорию 'дурацкий', но спросить не у кого :-( NT 4 - MTS W2000 - COM+ dotNET- ? Что нового дает технология 'сервисов' для создания компонентов 'среднего'...
debutant
ADO.NET - не могу вывести данные в DataGrid
Приветствую Всех! Помогите, ПЛЗ, с такой проблемой. Я только знакомлюсь с VB.NET и хотел попробовать подцепиться к базе на SQL2000. Создал OLEDBConnection, OLEDBDataAdapter, DataSet, но никак не...
Andros
Проблемы .NET с WinXP
У меня стоит ос WinXP, Его .Нет не знает и при установке пытается инсталлировать всякие там сервиспаки, как для Вин2000, система ему Ессно не позволяет и установка не продлевается. Но это ещё не всё!...
AlleXXX
Visual Basic 7.0 .NET
где найти документацию по Visual Basic 7.0 и download
lenchik_l



Текущее время: 12:07. Часовой пояс GMT +4.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

Рейтинг@Mail.ru