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

Discussion in 'ASP .Net Building Controls' started by Jc Morin, Dec 4, 2003.

  1. Jc Morin

    Jc Morin Guest

    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 :(
     
    Jc Morin, Dec 4, 2003
    #1
    1. Advertising

  2. Jc Morin

    Jc Morin Guest

    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





    "Jc Morin" <> wrote in message
    news:...
    > 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 :(
    >
    >
     
    Jc Morin, Dec 5, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    436
    Alf P. Steinbach
    May 23, 2007
  2. Replies:
    1
    Views:
    423
    myork
    May 23, 2007
  3. Replies:
    1
    Views:
    410
    Victor Bazarov
    May 23, 2007
  4. jobs
    Replies:
    0
    Views:
    1,764
  5. Earl Teigrob
    Replies:
    1
    Views:
    444
    Shravan
    Mar 1, 2004
Loading...

Share This Page