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

Логин

Email:
  Пароль:

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

Поиск

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

Книги по теме

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

Исходник

Автор:

Max Pro

 
Название:

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

Дата: 05 March 2005
Описание: Более функциональный чем предыдущий элемент управления. Я добавил возможность отдельно регулировать стили для текстбокса и строки состояния нумератора в целом. И в случае отсутствия ширины Width у строки состояния нумератора, привязал ширину к ширине таблицы. Если Вы установите ширишу таблицы больше нуля, то нумератор выровнится в левую сторону. Всё это видно в дизайнере. 
  Разместить ссылку на этот исходник в форуме вы можете вставив в текст сообщения следующую строку: [CODEPOST ID=131]WebCustomControl - более крутое расширение DataGrid - с дополнительным нумератором страниц[/CODEPOST]
Оценка: Проголосовало 5 посетителей, средняя оценка 4.60
Оценить:
  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 REM Пространство имён MaxPro
  8 Namespace MaxPro
  9     REM Класс, наследующий от DataGrid
 10     Public Class MaxProDataGrid2
 11         Inherits DataGrid
 12         Implements IPostBackEventHandler
 13         REM Область определения переменных уровня класса
 14         'далее определяются элементы строки состояния для датагрида
 15         Private oTextBoxTop As New TextBox  'текущая страница (верх)
 16         Private oTextBoxBottom As New TextBox 'текущая страница (низ)
 17         Private oLabel1Top As New Label 'страницы: (верх)
 18         Private oLabel2Top As New Label 'из 1000 (верх)
 19         Private oImageButton1Top As New ImageButton '<< (верх)
 20         Private oImageButton2Top As New ImageButton '< (верх)
 21         Private oImageButton3Top As New ImageButton '> (верх)
 22         Private oImageButton4Top As New ImageButton '>> (верх)
 23         Private oLabel1Bottom As New Label 'страницы: (низ)
 24         Private oLabel2Bottom As New Label 'из 1000 (низ)
 25         Private oImageButton1Bottom As New ImageButton '<< (низ)
 26         Private oImageButton2Bottom As New ImageButton '< (низ)
 27         Private oImageButton3Bottom As New ImageButton '> (низ)
 28         Private oImageButton4Bottom As New ImageButton '>> (низ)
 29         Private oTableTop As New Table 'верхняя строка состояния
 30         Private oTableBottom As New Table 'нижняя строка состояния
 31         'конец элементов датагрида
 32         REM Свойства
 33         'группа свойств типа строки состояния
 34         Private _customPager As New PagingStyle
 35         <DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
 36         NotifyParentProperty(True), _
 37         PersistenceMode(PersistenceMode.InnerProperty), _
 38         Category("Style"), _
 39         Description("Определяет свойства строки состояния CustomPaging")> _
 40         Public ReadOnly Property CustomPager() As PagingStyle
 41             Get
 42                 Return _customPager
 43             End Get
 44         End Property
 45         REM Применение стилей
 46         Private Sub setStyle()
 47             oTextBoxTop.Width = Unit.Pixel(50)
 48             oTextBoxTop.Height = Unit.Empty
 49             oTextBoxTop.Style.Add("vertical-align", "middle")
 50             oTextBoxTop.Style.Add("text-align", "center")
 51             oTextBoxTop.ApplyStyle(_customPager.TextBoxStyle)
 52             oTextBoxBottom.Width = Unit.Pixel(50)
 53             oTextBoxBottom.Height = Unit.Empty
 54             oTextBoxBottom.Style.Add("vertical-align", "middle")
 55             oTextBoxBottom.Style.Add("text-align", "center")
 56             oTextBoxBottom.ApplyStyle(_customPager.TextBoxStyle)
 57         End Sub
 58         REM Заполнение значений
 59         Private Sub setValue()
 60             'верх
 61             oTableTop = New Table
 62             oTableTop.ID = "oTableTop"
 63             oLabel1Top.Text = _customPager.TextFirst & " "
 64             oImageButton1Top.ImageUrl = _customPager.ImageFirstUrl
 65             oImageButton1Top.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton1")
 66             oImageButton2Top.ImageUrl = _customPager.ImageLeftUrl
 67             oImageButton2Top.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton2")
 68             oTextBoxTop.Text = CurrentPageIndex + 1
 69             oTextBoxTop.Attributes("onblur") = Page.GetPostBackEventReference(Me, "oTextBoxTop")
 70             oImageButton3Top.ImageUrl = _customPager.ImageRightUrl
 71             oImageButton3Top.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton3")
 72             oImageButton4Top.ImageUrl = _customPager.ImageLastUrl
 73             oImageButton4Top.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton4")
 74             oLabel2Top.Text = " " & _customPager.TextLast & " " & PageCount
 75             Dim oCell1Top As New TableCell
 76             Dim oCell2Top As New TableCell
 77             Dim oCell3Top As New TableCell
 78             Dim oCell4Top As New TableCell
 79             Dim oCell5Top As New TableCell
 80             Dim oCell6Top As New TableCell
 81             Dim oCell7Top As New TableCell
 82             Dim oCell8Top As New TableCell
 83             oCell1Top.Style.Add("vertical-align", "middle")
 84             oCell2Top.Style.Add("vertical-align", "middle")
 85             oCell3Top.Style.Add("vertical-align", "middle")
 86             oCell4Top.Style.Add("vertical-align", "middle")
 87             oCell5Top.Style.Add("vertical-align", "middle")
 88             oCell6Top.Style.Add("vertical-align", "middle")
 89             oCell7Top.Style.Add("vertical-align", "middle")
 90             oCell1Top.Style.Add("text-align", "center")
 91             oCell2Top.Style.Add("text-align", "center")
 92             oCell3Top.Style.Add("text-align", "center")
 93             oCell4Top.Style.Add("text-align", "center")
 94             oCell5Top.Style.Add("text-align", "center")
 95             oCell6Top.Style.Add("text-align", "center")
 96             oCell7Top.Style.Add("text-align", "center")
 97             oCell1Top.Wrap = False
 98             oCell7Top.Wrap = False
 99             oCell8Top.Width = Unit.Percentage(100)
100             oCell1Top.Controls.Add(oLabel1Top)
101             oCell2Top.Controls.Add(oImageButton1Top)
102             oCell3Top.Controls.Add(oImageButton2Top)
103             oCell4Top.Controls.Add(oTextBoxTop)
104             oCell5Top.Controls.Add(oImageButton3Top)
105             oCell6Top.Controls.Add(oImageButton4Top)
106             oCell7Top.Controls.Add(oLabel2Top)
107             Dim oRowTop As New TableRow
108             oRowTop.Cells.Add(oCell1Top)
109             oRowTop.Cells.Add(oCell2Top)
110             oRowTop.Cells.Add(oCell3Top)
111             oRowTop.Cells.Add(oCell4Top)
112             oRowTop.Cells.Add(oCell5Top)
113             oRowTop.Cells.Add(oCell6Top)
114             oRowTop.Cells.Add(oCell7Top)
115             If _customPager.Width.IsEmpty And (Not Width.IsEmpty) Then oRowTop.Cells.Add(oCell8Top)
116             oTableTop.Rows.Add(oRowTop)
117             oTableTop.Width = Width
118             oTableTop.ApplyStyle(_customPager)
119             'низ
120             oTableBottom = New Table
121             oTableBottom.ID = "oTableBottom"
122             oLabel1Bottom.Text = _customPager.TextFirst & " "
123             oImageButton1Bottom.ImageUrl = _customPager.ImageFirstUrl
124             oImageButton1Bottom.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton1")
125             oImageButton2Bottom.ImageUrl = _customPager.ImageLeftUrl
126             oImageButton2Bottom.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton2")
127             oTextBoxBottom.Text = CurrentPageIndex + 1
128             oTextBoxBottom.Attributes("onblur") = Page.GetPostBackEventReference(Me, "oTextBoxBottom")
129             oImageButton3Bottom.ImageUrl = _customPager.ImageRightUrl
130             oImageButton3Bottom.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton3")
131             oImageButton4Bottom.ImageUrl = _customPager.ImageLastUrl
132             oImageButton4Bottom.Attributes("onclick") = Page.GetPostBackEventReference(Me, "oImageButton4")
133             oLabel2Bottom.Text = " " & _customPager.TextLast & " " & PageCount
134             Dim oCell1Bottom As New TableCell
135             Dim oCell2Bottom As New TableCell
136             Dim oCell3Bottom As New TableCell
137             Dim oCell4Bottom As New TableCell
138             Dim oCell5Bottom As New TableCell
139             Dim oCell6Bottom As New TableCell
140             Dim oCell7Bottom As New TableCell
141             Dim oCell8Bottom As New TableCell
142             oCell1Bottom.Style.Add("vertical-align", "middle")
143             oCell2Bottom.Style.Add("vertical-align", "middle")
144             oCell3Bottom.Style.Add("vertical-align", "middle")
145             oCell4Bottom.Style.Add("vertical-align", "middle")
146             oCell5Bottom.Style.Add("vertical-align", "middle")
147             oCell6Bottom.Style.Add("vertical-align", "middle")
148             oCell7Bottom.Style.Add("vertical-align", "middle")
149             oCell1Bottom.Style.Add("text-align", "center")
150             oCell2Bottom.Style.Add("text-align", "center")
151             oCell3Bottom.Style.Add("text-align", "center")
152             oCell4Bottom.Style.Add("text-align", "center")
153             oCell5Bottom.Style.Add("text-align", "center")
154             oCell6Bottom.Style.Add("text-align", "center")
155             oCell7Bottom.Style.Add("text-align", "center")
156             oCell1Bottom.Wrap = False
157             oCell7Bottom.Wrap = False
158             oCell8Bottom.Width = Unit.Percentage(100)
159             oCell1Bottom.Controls.Add(oLabel1Bottom)
160             oCell2Bottom.Controls.Add(oImageButton1Bottom)
161             oCell3Bottom.Controls.Add(oImageButton2Bottom)
162             oCell4Bottom.Controls.Add(oTextBoxBottom)
163             oCell5Bottom.Controls.Add(oImageButton3Bottom)
164             oCell6Bottom.Controls.Add(oImageButton4Bottom)
165             oCell7Bottom.Controls.Add(oLabel2Bottom)
166             Dim oRowBottom As New TableRow
167             oRowBottom.Cells.Add(oCell1Bottom)
168             oRowBottom.Cells.Add(oCell2Bottom)
169             oRowBottom.Cells.Add(oCell3Bottom)
170             oRowBottom.Cells.Add(oCell4Bottom)
171             oRowBottom.Cells.Add(oCell5Bottom)
172             oRowBottom.Cells.Add(oCell6Bottom)
173             oRowBottom.Cells.Add(oCell7Bottom)
174             If _customPager.Width.IsEmpty And (Not Width.IsEmpty) Then oRowBottom.Cells.Add(oCell8Bottom)
175             oTableBottom.Rows.Add(oRowBottom)
176             oTableBottom.Width = Width
177             oTableBottom.ApplyStyle(_customPager)
178         End Sub
179         REM Формирование дочерних элементов управления
180         Protected Overrides Sub CreateChildControls()
181             oTextBoxTop.ID = "oTextBoxTop"
182             oTextBoxBottom.ID = "oTextBoxBottom"
183             Controls.Add(oTextBoxTop)
184             Controls.Add(oTextBoxBottom)
185         End Sub
186         REM Добавление строки состояния
187         Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
188             setStyle()
189             setValue()
190             Dim sBorder As String = _customPager.BorderColor.Name & " " & _customPager.BorderWidth.ToString & " " & _customPager.BorderStyle
191             If (_customPager.Visible And PagerStyle.Position = PagerPosition.Top) Or (_customPager.Visible And PagerStyle.Position = PagerPosition.TopAndBottom) Then
192                 oTableTop.RenderControl(writer)
193             End If
194             MyBase.Render(writer)
195             If (_customPager.Visible And PagerStyle.Position = PagerPosition.Bottom) Or (_customPager.Visible And PagerStyle.Position = PagerPosition.TopAndBottom) Then
196                 oTableBottom.RenderControl(writer)
197             End If
198             If _customPager.Width.IsEmpty Then
199                 Dim sScript As String
200                 Dim sFunction As String = ""
201                 sScript = Chr(10)
202                 sScript &= "<script language='javascript'>" & Chr(10)
203                 sScript &= "<!--" & Chr(10)
204                 If (_customPager.Visible And PagerStyle.Position = PagerPosition.Top) Or (_customPager.Visible And PagerStyle.Position = PagerPosition.TopAndBottom) Then
205                     sScript &= "    " & oTableTop.ClientID & ".style.width=" & ClientID & ".offsetWidth;" & Chr(10)
206                     sFunction = oTableTop.ClientID & ".style.width=" & ClientID & ".offsetWidth;"
207                 End If
208                 If (_customPager.Visible And PagerStyle.Position = PagerPosition.Bottom) Or (_customPager.Visible And PagerStyle.Position = PagerPosition.TopAndBottom) Then
209                     sScript &= "    " & oTableBottom.ClientID & ".style.width=" & ClientID & ".offsetWidth;" & Chr(10)
210                     sFunction &= oTableBottom.ClientID & ".style.width=" & ClientID & ".offsetWidth;"
211                 End If
212                 If sFunction <> "" Then
213                     sScript &= "    " & ClientID & ".onresize=function(){" & sFunction & "};" & Chr(10)
214                 End If
215                 sScript &= "// -->" & Chr(10)
216                 sScript &= "</script>" & Chr(10)
217                 Page.RegisterStartupScript("oTable", sScript)
218             End If
219         End Sub
220         REM Обработка обратного запроса
221         Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
222             Select Case eventArgument
223                 Case "oTextBoxTop"
224                     Dim s As String = Page.Request.Form(oTextBoxTop.ID)
225                     If IsNumeric(s) Then
226                         If s > 0 And s <= PageCount Then
227                             CurrentPageIndex = s - 1
228                             DataBind()
229                         End If
230                     End If
231                 Case "oTextBoxBottom"
232                     Dim s As String = Page.Request.Form(oTextBoxBottom.ID)
233                     If IsNumeric(s) Then
234                         If s > 0 And s <= PageCount Then
235                             CurrentPageIndex = s - 1
236                             DataBind()
237                         End If
238                     End If
239                 Case "oImageButton1"
240                     CurrentPageIndex = 0
241                     DataBind()
242                 Case "oImageButton2"
243                     If CurrentPageIndex > 0 Then CurrentPageIndex -= 1
244                     DataBind()
245                 Case "oImageButton3"
246                     If CurrentPageIndex < (PageCount - 1) Then CurrentPageIndex += 1
247                     DataBind()
248                 Case "oImageButton4"
249                     CurrentPageIndex = PageCount - 1
250                     DataBind()
251             End Select
252         End Sub
253     End Class
254     REM Стилевой класс, определяющий свойства строки состояния CustomPaging
255     Public Class PagingStyle
256         Inherits Style
257         REM Дополнительные свойства
258         'Visible:
259         Private _visible As Boolean = True
260         <DefaultValue(True), _
261         NotifyParentProperty(True), _
262         Description("Определяет видимость строки состояния CustomPaging")> _
263         Public Property Visible() As Boolean
264             Get
265                 Return _visible
266             End Get
267             Set(ByVal Value As Boolean)
268                 _visible = Value
269             End Set
270         End Property
271         'страницы:
272         Private _textFirst As String = "Страницы:"
273         <DefaultValue("Страницы:"), _
274         NotifyParentProperty(True), _
275         Description("Определяет наименование строки состояния CustomPaging")> _
276         Public Property TextFirst() As String
277             Get
278                 Return _textFirst
279             End Get
280             Set(ByVal Value As String)
281                 _textFirst = Value
282             End Set
283         End Property
284         'из 1000
285         Private _textLast As String = "из"
286         <DefaultValue("из"), _
287         NotifyParentProperty(True), _
288         Description("Определяет окончание строки состояния CustomPaging")> _
289         Public Property TextLast() As String
290             Get
291                 Return _textLast
292             End Get
293             Set(ByVal Value As String)
294                 _textLast = Value
295             End Set
296         End Property
297         'url <<
298         Private _imageFirstUrl As String = "/Img/First.gif"
299         <DefaultValue("/Img/First.gif"), _
300         NotifyParentProperty(True), _
301         Description("Url картинки 'первая' строки состояния CustomPaging")> _
302         Public Property ImageFirstUrl() As String
303             Get
304                 Return _imageFirstUrl
305             End Get
306             Set(ByVal Value As String)
307                 _imageFirstUrl = Value
308             End Set
309         End Property
310         'url >>
311         Private _imageLastUrl As String = "/Img/Last.gif"
312         <DefaultValue("/Img/Last.gif"), _
313         NotifyParentProperty(True), _
314         Description("Url картинки 'последняя' строки состояния CustomPaging")> _
315         Public Property ImageLastUrl() As String
316             Get
317                 Return _imageLastUrl
318             End Get
319             Set(ByVal Value As String)
320                 _imageLastUrl = Value
321             End Set
322         End Property
323         'url <
324         Private _imageLeftUrl As String = "/Img/Left.gif"
325         <DefaultValue("/Img/Left.gif"), _
326         NotifyParentProperty(True), _
327         Description("Url картинки '-1' строки состояния CustomPaging")> _
328         Public Property ImageLeftUrl() As String
329             Get
330                 Return _imageLeftUrl
331             End Get
332             Set(ByVal Value As String)
333                 _imageLeftUrl = Value
334             End Set
335         End Property
336         'url >
337         Private _imageRightUrl As String = "/Img/Right.gif"
338         <DefaultValue("/Img/Right.gif"), _
339         NotifyParentProperty(True), _
340         Description("Url картинки '+1' строки состояния CustomPaging")> _
341         Public Property ImageRightUrl() As String
342             Get
343                 Return _imageRightUrl
344             End Get
345             Set(ByVal Value As String)
346                 _imageRightUrl = Value
347             End Set
348         End Property
349         'Стиль текстбокса
350         Private _textboxStyle As New Style
351         <DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
352         NotifyParentProperty(True), _
353         PersistenceMode(PersistenceMode.InnerProperty), _
354         Category("Style"), _
355         Description("Определяет свойства строки состояния CustomPaging")> _
356         Public ReadOnly Property TextBoxStyle() As Style
357             Get
358                 Return _textboxStyle
359             End Get
360         End Property
361     End Class
362 End Namespace
363 
Вернуться к списку исходников в категории Создание элементов управления
 
Apartments for Rent

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