Override Datagrid from function

Y

Yuriy Solodkyy

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
 
R

Ralf Rennartz

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
 
Y

Yuriy Solodkyy

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
 
R

Ralf Rennartz

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
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top