Control derived from datagrid, problem with adding other control and databinding (VB)

J

Jc Morin

I all, my employer required me to add a bunch of control to a datagrid (such
as a drop down list on top corner to select page size and prev, bunch page
number adapted to current page, next and other button like export to excel).

All of those control do not required databinding (except of course the base
class Datagrid)
All of those control don't need view state (I will deal with current page
and stuff internaly)

We are already using the .NET datagrid with template so I create a control
that *derived* from the datagrid.

I feel some problem with
- Event from the dropdownlist
- Event from the button added
- Databinding to the base class (DataGrid)

I have only 2 of 3 working at the same time (any combinaison)!!!
If I have only dropdownlist and databinding it work, if I add a button in
the created child control.
I get some other stuff not working.

___
cmdBut = New LinkButton
cmdBut.Text = "Previous"
cmdBut.EnableViewState = False
AddHandler cmdBut.Click, AddressOf SomeActionButton_Click
Me.Controls.Add(cmdBut)
___


I don't need help about composite control that start from strach and add
their control, I need to keep DataGrid method and content working well.

Here is some questions in my head.

Should my control derived from a Datagrid or be composite and have a
Datagrid as member?
Do I have to implements IPostBackDataHandler? (for the dropdownlist maybe)
Do I have to implements IPostBackEventHandler? (for the button maybe)
Shoud I Controls.Clear() in the CreateChildControls() ? (droping my
Datagrid)
I have to overrides CreateControlHierarchy and PrepareControlHierarchy ?
I have to overrides Databind() ?


I would like to have a sample code or help about how to deal with this, else
I gonna copy paste the additive control all over my page :(
 
J

Jc Morin

Here is some code to help you helping me :)


Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class PagingDataGrid
Inherits System.Web.UI.WebControls.DataGrid

Protected lstPageSize As New WebControls.DropDownList
Protected cmdPrevious As New LinkButton
Protected cmdNext As New LinkButton


Private Sub InitializeComponent()
Me.EnableViewState = False
End Sub


Protected Overrides Sub CreateChildControls()
'Controls.Clear() ' make everything not working
AddOtherControl()
End Sub

Private Sub AddOtherControl()
If Not (Me.Controls.Contains(lstPageSize)) Then
lstPageSize = New WebControls.DropDownList
lstPageSize.AutoPostBack = True
lstPageSize.EnableViewState = False
lstPageSize.Items.Add("1")
lstPageSize.Items.Add("2")
lstPageSize.Items.Add("3")

AddHandler lstPageSize.SelectedIndexChanged, AddressOf
lstPageSize_SelectedIndexChanged
Controls.Add(lstPageSize)

cmdPrevious = New LinkButton
cmdPrevious.Text = "Previous"
cmdPrevious.EnableViewState = False
AddHandler cmdPrevious.Click, AddressOf PreviousButton_Click
Controls.Add(cmdPrevious)

' ----------------********************-----------------
' adding this make everything not working
'cmdNext = New LinkButton
'cmdNext.Text = "Next"
'cmdNext.EnableViewState = False
'AddHandler cmdNext.Click, AddressOf NextButton_Click
'Controls.Add(cmdNext)


End If

End Sub

Private Sub lstPageSize_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs)
Dim setbreakpointhere as Integer = 1
End Sub

Private Sub PreviousButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim setbreakpointhere as Integer = 1
End Sub

Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim setbreakpointhere as Integer = 1
End Sub

Private Sub PagingDataGrid_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
MyBase.ItemDataBound
CreateChildControls()
ChildControlsCreated = True
End Sub

End Class
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top