Override Datagrid from function

Discussion in 'ASP .Net' started by Yuriy Solodkyy, Jun 11, 2007.

  1. Hi

    Do you add your newly created control to the page? If you create your control
    dynamically you need to add it to the page. The simplest way is to put a
    PlaceHolder control at your web page and add your grid to the control by
    calling:

    PlaceHolder1.Controls.Add(myGrid)


    -yuriy

    > Hello NG,
    >
    > i have the following function which works fine:
    >
    > Public Shared Function getFullDatagrid() As
    > System.Web.UI.WebControls.DataGrid
    >
    > Dim myGrid As New System.Web.UI.WebControls.DataGrid()
    >
    > Dim bcn1 As New BoundColumn()
    >
    > bcn1.HeaderText = "T55"
    >
    > bcn1.DataField = "DocumentID"
    >
    > myGrid.Columns.Add(bcn1)
    >
    > myGrid.Enabled = True
    >
    > myGrid.EnableViewState = True
    >
    > myGrid.DataSource = getData("test")
    >
    > myGrid.DataBind()
    >
    > Return myGrid
    >
    > End Function
    >
    > In Page_Load i call the function:
    >
    > DataGrid1 = getFullDatagrid()
    >
    > But the datagrid is not displayed. All the propertys like
    > "DataGrid1.Columns.Count" , "DataGrid1.Items.Count" can be shown in a
    > layer.
    >
    > Do you know what is going wrong here?
    >
    > Thank You
    > Ralf
     
    Yuriy Solodkyy, Jun 11, 2007
    #1
    1. Advertising

  2. Hello NG,

    i have the following function which works fine:

    Public Shared Function getFullDatagrid() As
    System.Web.UI.WebControls.DataGrid

    Dim myGrid As New System.Web.UI.WebControls.DataGrid()

    Dim bcn1 As New BoundColumn()

    bcn1.HeaderText = "T55"

    bcn1.DataField = "DocumentID"

    myGrid.Columns.Add(bcn1)

    myGrid.Enabled = True

    myGrid.EnableViewState = True

    myGrid.DataSource = getData("test")

    myGrid.DataBind()

    Return myGrid

    End Function


    In Page_Load i call the function:

    DataGrid1 = getFullDatagrid()

    But the datagrid is not displayed. All the propertys like
    "DataGrid1.Columns.Count" , "DataGrid1.Items.Count" can be shown in a
    layer.

    Do you know what is going wrong here?

    Thank You
    Ralf
     
    Ralf Rennartz, Jun 11, 2007
    #2
    1. Advertising

  3. As you create new instance of the control you still need to add this newly
    added control to the page. You may try adding it to the same parent control
    as the old one which is created by the designer.

    Try something like:

    Dim temp as DataGrid
    temp = DataGrid1
    DataGrid1 = getFullDatagrid()
    temp.Parent.Controls.Add(DataGrid1)

    However, I owuld recommend replacing the grid created in designer with PlaceHolder
    control and then using dynamic control by adding it to the placeholder.

    -yuriy

    > Hello,
    >
    > i have created a datagrid in designview in VS:
    >
    > Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    > ......
    >
    > ' --- This works: DataGrid1 = getData("test")
    >
    > 'This seems to be work fine, but it isnt shown on the screen DataGrid1
    > = getFullDatagrid()
    >
    > Hope You understand what i mean.
    >
    > Ralf
    >
    > "Yuriy Solodkyy" <> schrieb im Newsbeitrag
    > news:...
    >
    >> Hi
    >>
    >> Do you add your newly created control to the page? If you create
    >> your control dynamically you need to add it to the page. The
    >> simplest way is to put a PlaceHolder control at your web page and add
    >> your grid to the control by calling:
    >>
    >> PlaceHolder1.Controls.Add(myGrid)
    >>
    >> -yuriy
    >>
    >>> Hello NG,
    >>>
    >>> i have the following function which works fine:
    >>>
    >>> Public Shared Function getFullDatagrid() As
    >>> System.Web.UI.WebControls.DataGrid
    >>> Dim myGrid As New System.Web.UI.WebControls.DataGrid()
    >>>
    >>> Dim bcn1 As New BoundColumn()
    >>>
    >>> bcn1.HeaderText = "T55"
    >>>
    >>> bcn1.DataField = "DocumentID"
    >>>
    >>> myGrid.Columns.Add(bcn1)
    >>>
    >>> myGrid.Enabled = True
    >>>
    >>> myGrid.EnableViewState = True
    >>>
    >>> myGrid.DataSource = getData("test")
    >>>
    >>> myGrid.DataBind()
    >>>
    >>> Return myGrid
    >>>
    >>> End Function
    >>>
    >>> In Page_Load i call the function:
    >>>
    >>> DataGrid1 = getFullDatagrid()
    >>>
    >>> But the datagrid is not displayed. All the propertys like
    >>> "DataGrid1.Columns.Count" , "DataGrid1.Items.Count" can be shown in
    >>> a layer.
    >>>
    >>> Do you know what is going wrong here?
    >>>
    >>> Thank You
    >>> Ralf
     
    Yuriy Solodkyy, Jun 11, 2007
    #3
  4. Hello,

    i have created a datagrid in designview in VS:

    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    .......


    ' --- This works: DataGrid1 = getData("test")

    'This seems to be work fine, but it isnt shown on the screen
    DataGrid1 = getFullDatagrid()


    Hope You understand what i mean.

    Ralf








    "Yuriy Solodkyy" <> schrieb im Newsbeitrag
    news:...
    > Hi
    >
    > Do you add your newly created control to the page? If you create your
    > control dynamically you need to add it to the page. The simplest way is
    > to put a PlaceHolder control at your web page and add your grid to the
    > control by calling:
    >
    > PlaceHolder1.Controls.Add(myGrid)
    >
    >
    > -yuriy
    >
    >> Hello NG,
    >>
    >> i have the following function which works fine:
    >>
    >> Public Shared Function getFullDatagrid() As
    >> System.Web.UI.WebControls.DataGrid
    >>
    >> Dim myGrid As New System.Web.UI.WebControls.DataGrid()
    >>
    >> Dim bcn1 As New BoundColumn()
    >>
    >> bcn1.HeaderText = "T55"
    >>
    >> bcn1.DataField = "DocumentID"
    >>
    >> myGrid.Columns.Add(bcn1)
    >>
    >> myGrid.Enabled = True
    >>
    >> myGrid.EnableViewState = True
    >>
    >> myGrid.DataSource = getData("test")
    >>
    >> myGrid.DataBind()
    >>
    >> Return myGrid
    >>
    >> End Function
    >>
    >> In Page_Load i call the function:
    >>
    >> DataGrid1 = getFullDatagrid()
    >>
    >> But the datagrid is not displayed. All the propertys like
    >> "DataGrid1.Columns.Count" , "DataGrid1.Items.Count" can be shown in a
    >> layer.
    >>
    >> Do you know what is going wrong here?
    >>
    >> Thank You
    >> Ralf

    >
    >
     
    Ralf Rennartz, Jun 11, 2007
    #4
  5. You are right: Placeholder works fine.
    Thanks!

    Greets
    Ralf





    "Yuriy Solodkyy" <> schrieb im Newsbeitrag
    news:...
    > Hi
    >
    > Do you add your newly created control to the page? If you create your
    > control dynamically you need to add it to the page. The simplest way is
    > to put a PlaceHolder control at your web page and add your grid to the
    > control by calling:
    >
    > PlaceHolder1.Controls.Add(myGrid)
    >
    >
    > -yuriy
    >
    >> Hello NG,
    >>
    >> i have the following function which works fine:
    >>
    >> Public Shared Function getFullDatagrid() As
    >> System.Web.UI.WebControls.DataGrid
    >>
    >> Dim myGrid As New System.Web.UI.WebControls.DataGrid()
    >>
    >> Dim bcn1 As New BoundColumn()
    >>
    >> bcn1.HeaderText = "T55"
    >>
    >> bcn1.DataField = "DocumentID"
    >>
    >> myGrid.Columns.Add(bcn1)
    >>
    >> myGrid.Enabled = True
    >>
    >> myGrid.EnableViewState = True
    >>
    >> myGrid.DataSource = getData("test")
    >>
    >> myGrid.DataBind()
    >>
    >> Return myGrid
    >>
    >> End Function
    >>
    >> In Page_Load i call the function:
    >>
    >> DataGrid1 = getFullDatagrid()
    >>
    >> But the datagrid is not displayed. All the propertys like
    >> "DataGrid1.Columns.Count" , "DataGrid1.Items.Count" can be shown in a
    >> layer.
    >>
    >> Do you know what is going wrong here?
    >>
    >> Thank You
    >> Ralf

    >
    >
     
    Ralf Rennartz, Jun 11, 2007
    #5
    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. Angus Comber
    Replies:
    3
    Views:
    839
    John Harrison
    Apr 10, 2004
  2. Angus Comber
    Replies:
    3
    Views:
    898
    John Harrison
    Apr 11, 2004
  3. Replies:
    2
    Views:
    970
    Bengt Richter
    Aug 1, 2005
  4. smcirish
    Replies:
    0
    Views:
    327
    smcirish
    Apr 22, 2008
  5. Peng Yu
    Replies:
    4
    Views:
    376
    peter koch
    Sep 20, 2008
Loading...

Share This Page