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

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

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

    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 Guest

  2. Similar Questions and Discussions

    1. Custom Templated Databound Control or derived control?
      Hi, I want to create a control that performs much like a datalist but I want more control over how the <ItemTemplate> contents is set out on the...
    2. Composite Web Custom Control derived from DataGrid
      Hello I am a beginner at creating composite web controls. What I am trying to do it add functionality to the DataGrid webcontrol by adding two...
    3. Custom DataGrid Control - problem with adding BoundColumn
      I have created a custom control that derives from a DataGrid: public class SelectableDataGridControl : System.Web.UI.WebControls.DataGrid I have...
    4. rendering derived control from composite control
      I am triing to load a control derived from a datagrid into a composite control so I can wrap some html around the datagrid. it renders the html in...
    5. Adding Columns at runtime in datagrid control
      have a datgrid control that has 3 columns defined at design time. Remaining columns are coming from a query and not known until runtime. I have...
  3. #2

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

    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" <jcmorin@2k1soft.com> wrote in message
    news:ueJuRRouDHA.2316@TK2MSFTNGP10.phx.gbl...
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139