Rambler's Top100
Главная
Новости
Статьи
Форумы
Книги
Коды
Сообщество
Блоги
О нас
 

Логин

Email:
  Пароль:

Войти
Зарегистрироваться
Забыл пароль

Поиск

 Искать :
 
Вперед

Книги по теме

Искать:
в:
Порядок:

Исходник

Автор:

Max Pro

 
Название:

WebCustomControl - расширение DataGrid - с дополнительным нумератором страниц

Дата: 04 March 2005
Описание: Это обычный DataGrid, но у которого есть дополнительная возможность подключения переключателя страниц как в Access. Свойства этой новой строки состояния находятся в группе CustomPagingStyle. Там же можно сделать Visible=False. Желаю приятной работы! 
  Разместить ссылку на этот исходник в форуме вы можете вставив в текст сообщения следующую строку: [CODEPOST ID=130]WebCustomControl - расширение DataGrid - с дополнительным нумератором страниц[/CODEPOST]
Оценка: Проголосовало 4 посетителей, средняя оценка 1.50
Оценить:
  1 Imports System
  2 Imports System.Web
  3 Imports System.Web.UI
  4 Imports System.Web.UI.WebControls
  5 Imports System.Drawing
  6 Imports System.ComponentModel
  7 
  8 REM Пространство имён MaxPro
  9 Namespace MaxPro
 10     REM Класс, наследующий от DataGrid
 11     Public Class MaxProDataGrid
 12         Inherits DataGrid
 13         Implements IPostBackEventHandler
 14         REM Область определения переменных уровня класса
 15         'далее определяются элементы строки состояния для датагрида
 16         Private oTextBoxTop As New TextBox  'текущая страница
 17         Private oTextBoxBottom As New TextBox 'текущая страница
 18         Private oLabel1 As New Label 'страницы:
 19         Private oLabel2 As New Label 'из 1000
 20         Private oImageButton1 As New ImageButton '<<
 21         Private oImageButton2 As New ImageButton '<
 22         Private oImageButton3 As New ImageButton '>
 23         Private oImageButton4 As New ImageButton '>>
 24         'конец элементов датагрида
 25         REM Свойства
 26         'группа свойств типа строки состояния
 27         Private _customPagingStyle As New PagingStyle
 28         <DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
 29         NotifyParentProperty(True), _
 30         PersistenceMode(PersistenceMode.InnerProperty), _
 31         Category("Style"), _
 32         Description("Определяет свойства строки состояния CustomPaging")> _
 33         Public ReadOnly Property CustomPagingStyle() As PagingStyle
 34             Get
 35                 Return _customPagingStyle
 36             End Get
 37         End Property
 38         REM Применение стилей
 39         Private Sub setStyle()
 40             oTextBoxTop.Width = Unit.Pixel(50)
 41             oTextBoxTop.Height = Unit.Empty
 42             oTextBoxTop.ApplyStyle(_customPagingStyle)
 43             oTextBoxBottom.Width = Unit.Pixel(50)
 44             oTextBoxBottom.Height = Unit.Empty
 45             oTextBoxBottom.ApplyStyle(_customPagingStyle)
 46             oLabel1.ApplyStyle(_customPagingStyle)
 47             oLabel1.Width = Unit.Empty
 48             oLabel1.Height = Unit.Empty
 49             oLabel1.BorderStyle = BorderStyle.None
 50             oLabel1.BackColor = Color.Empty
 51             oLabel2.ApplyStyle(_customPagingStyle)
 52             oLabel2.Width = Unit.Empty
 53             oLabel2.Height = Unit.Empty
 54             oLabel2.BorderStyle = BorderStyle.None
 55             oLabel2.BackColor = Color.Empty
 56         End Sub
 57         REM Заполнение значений
 58         Private Sub setValue()
 59             oLabel1.Text = _customPagingStyle.TextFirst & " "
 60             oImageButton1.ImageUrl = _customPagingStyle.ImageFirstUrl
 61             oImageButton1.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton1")
 62             oImageButton2.ImageUrl = _customPagingStyle.ImageLeftUrl
 63             oImageButton2.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton2")
 64             oTextBoxTop.Text = CurrentPageIndex + 1
 65             oTextBoxTop.Attributes("onblur") = Page.GetPostBackEventReference(Me, "oTextBoxTop")
 66             oTextBoxBottom.Text = CurrentPageIndex + 1
 67             oTextBoxBottom.Attributes("onblur") = Page.GetPostBackEventReference(Me, "oTextBoxBottom")
 68             oImageButton3.ImageUrl = _customPagingStyle.ImageRightUrl
 69             oImageButton3.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton3")
 70             oImageButton4.ImageUrl = _customPagingStyle.ImageLastUrl
 71             oImageButton4.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton4")
 72             oLabel2.Text = " " & _customPagingStyle.TextLast & " " & PageCount
 73         End Sub
 74         REM Формирование дочерних элементов управления
 75         Protected Overrides Sub CreateChildControls()
 76             oTextBoxTop.ID = "oTextBoxTop"
 77             oTextBoxBottom.ID = "oTextBoxBottom"
 78             Controls.Add(oTextBoxTop)
 79             Controls.Add(oTextBoxBottom)
 80         End Sub
 81         REM Добавление строки состояния
 82         Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
 83             setStyle()
 84             setValue()
 85             If (_customPagingStyle.Visible And PagerStyle.Position = PagerPosition.Top) Or (_customPagingStyle.Visible And PagerStyle.Position = PagerPosition.TopAndBottom) Then
 86                 writer.RenderBeginTag("table")
 87                 writer.RenderBeginTag("tr")
 88                 writer.AddStyleAttribute("vertical-align", "middle")
 89                 writer.RenderBeginTag("td")
 90                 oLabel1.RenderControl(writer)
 91                 writer.RenderEndTag() 'td
 92                 writer.AddStyleAttribute("vertical-align", "middle")
 93                 writer.RenderBeginTag("td")
 94                 oImageButton1.RenderControl(writer)
 95                 oImageButton2.RenderControl(writer)
 96                 writer.RenderEndTag() 'td
 97                 writer.AddStyleAttribute("vertical-align", "middle")
 98                 writer.RenderBeginTag("td")
 99                 oTextBoxTop.RenderControl(writer)
100                 writer.RenderEndTag() 'td
101                 writer.AddStyleAttribute("vertical-align", "middle")
102                 writer.RenderBeginTag("td")
103                 oImageButton3.RenderControl(writer)
104                 oImageButton4.RenderControl(writer)
105                 writer.RenderEndTag() 'td
106                 writer.AddStyleAttribute("vertical-align", "middle")
107                 writer.RenderBeginTag("td")
108                 oLabel2.RenderControl(writer)
109                 writer.RenderEndTag() 'td
110                 writer.RenderEndTag() 'tr
111                 writer.RenderEndTag() 'table
112             End If
113             MyBase.Render(writer)
114             If (_customPagingStyle.Visible And PagerStyle.Position = PagerPosition.Bottom) Or (_customPagingStyle.Visible And PagerStyle.Position = PagerPosition.TopAndBottom) Then
115                 writer.RenderBeginTag("table")
116                 writer.RenderBeginTag("tr")
117                 writer.AddStyleAttribute("vertical-align", "middle")
118                 writer.RenderBeginTag("td")
119                 oLabel1.RenderControl(writer)
120                 writer.RenderEndTag() 'td
121                 writer.AddStyleAttribute("vertical-align", "middle")
122                 writer.RenderBeginTag("td")
123                 oImageButton1.RenderControl(writer)
124                 oImageButton2.RenderControl(writer)
125                 writer.RenderEndTag() 'td
126                 writer.AddStyleAttribute("vertical-align", "middle")
127                 writer.RenderBeginTag("td")
128                 oTextBoxBottom.RenderControl(writer)
129                 writer.RenderEndTag() 'td
130                 writer.AddStyleAttribute("vertical-align", "middle")
131                 writer.RenderBeginTag("td")
132                 oImageButton3.RenderControl(writer)
133                 oImageButton4.RenderControl(writer)
134                 writer.RenderEndTag() 'td
135                 writer.AddStyleAttribute("vertical-align", "middle")
136                 writer.RenderBeginTag("td")
137                 oLabel2.RenderControl(writer)
138                 writer.RenderEndTag() 'td
139                 writer.RenderEndTag() 'tr
140                 writer.RenderEndTag() 'table
141             End If
142         End Sub
143         REM Обработка обратного запроса
144         Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
145             Select Case eventArgument
146                 Case "oTextBoxTop"
147                     Dim s As String = Page.Request.Form(oTextBoxTop.ID)
148                     If IsNumeric(s) Then
149                         If s > 0 And s <= PageCount Then
150                             CurrentPageIndex = s - 1
151                             DataBind()
152                         End If
153                     End If
154                 Case "oTextBoxBottom"
155                     Dim s As String = Page.Request.Form(oTextBoxBottom.ID)
156                     If IsNumeric(s) Then
157                         If s > 0 And s <= PageCount Then
158                             CurrentPageIndex = s - 1
159                             DataBind()
160                         End If
161                     End If
162                 Case "oImageButton1"
163                     CurrentPageIndex = 0
164                     DataBind()
165                 Case "oImageButton2"
166                     If CurrentPageIndex > 0 Then CurrentPageIndex -= 1
167                     DataBind()
168                 Case "oImageButton3"
169                     If CurrentPageIndex < (PageCount - 1) Then CurrentPageIndex += 1
170                     DataBind()
171                 Case "oImageButton4"
172                     CurrentPageIndex = PageCount - 1
173                     DataBind()
174             End Select
175         End Sub
176     End Class
177     REM Стилевой класс, определяющий свойства строки состояния CustomPaging
178     Public Class PagingStyle
179         Inherits Style
180         REM Дополнительные свойства
181         'Visible:
182         Private _visible As Boolean = True
183         <DefaultValue(True), _
184         NotifyParentProperty(True), _
185         Description("Определяет видимость строки состояния CustomPaging")> _
186         Public Property Visible() As Boolean
187             Get
188                 Return _visible
189             End Get
190             Set(ByVal Value As Boolean)
191                 _visible = Value
192             End Set
193         End Property
194         'страницы:
195         Private _textFirst As String = "Страницы:"
196         <DefaultValue("Страницы:"), _
197         NotifyParentProperty(True), _
198         Description("Определяет наименование строки состояния CustomPaging")> _
199         Public Property TextFirst() As String
200             Get
201                 Return _textFirst
202             End Get
203             Set(ByVal Value As String)
204                 _textFirst = Value
205             End Set
206         End Property
207         'из 1000
208         Private _textLast As String = "из"
209         <DefaultValue("из"), _
210         NotifyParentProperty(True), _
211         Description("Определяет окончание строки состояния CustomPaging")> _
212         Public Property TextLast() As String
213             Get
214                 Return _textLast
215             End Get
216             Set(ByVal Value As String)
217                 _textLast = Value
218             End Set
219         End Property
220         'url <<
221         Private _imageFirstUrl As String = "/Img/First.gif"
222         <DefaultValue("/Img/First.gif"), _
223         NotifyParentProperty(True), _
224         Description("Url картинки 'первая' строки состояния CustomPaging")> _
225         Public Property ImageFirstUrl() As String
226             Get
227                 Return _imageFirstUrl
228             End Get
229             Set(ByVal Value As String)
230                 _imageFirstUrl = Value
231             End Set
232         End Property
233         'url >>
234         Private _imageLastUrl As String = "/Img/Last.gif"
235         <DefaultValue("/Img/Last.gif"), _
236         NotifyParentProperty(True), _
237         Description("Url картинки 'последняя' строки состояния CustomPaging")> _
238         Public Property ImageLastUrl() As String
239             Get
240                 Return _imageLastUrl
241             End Get
242             Set(ByVal Value As String)
243                 _imageLastUrl = Value
244             End Set
245         End Property
246         'url <
247         Private _imageLeftUrl As String = "/Img/Left.gif"
248         <DefaultValue("/Img/Left.gif"), _
249         NotifyParentProperty(True), _
250         Description("Url картинки '-1' строки состояния CustomPaging")> _
251         Public Property ImageLeftUrl() As String
252             Get
253                 Return _imageLeftUrl
254             End Get
255             Set(ByVal Value As String)
256                 _imageLeftUrl = Value
257             End Set
258         End Property
259         'url >
260         Private _imageRightUrl As String = "/Img/Right.gif"
261         <DefaultValue("/Img/Right.gif"), _
262         NotifyParentProperty(True), _
263         Description("Url картинки '+1' строки состояния CustomPaging")> _
264         Public Property ImageRightUrl() As String
265             Get
266                 Return _imageRightUrl
267             End Get
268             Set(ByVal Value As String)
269                 _imageRightUrl = Value
270             End Set
271         End Property
272     End Class
273 End Namespace
274 
Вернуться к списку исходников в категории Создание элементов управления
 
Наш Киев

Apartments for Rent

Rambler's Top100
Рейтинг@Mail.ru
Идея: Dimon aka Manowar Программирование: Dimon aka Manowar Дизайн: Dan Lebedev
Хостинг от компании Parking.ru
Карта сайта