By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,685 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,685 IT Pros & Developers. It's quick & easy.

Override Datagrid from function

P: n/a
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
Jun 11 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Jun 11 '07 #2

P: n/a
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" <y.************@gmail.comschrieb im Newsbeitrag
news:57***************************@msnews.microsof t.com...
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


Jun 11 '07 #3

P: n/a

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" <y.************@gmail.comschrieb im Newsbeitrag
news:57***************************@msnews.microsof t.com...
>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

Jun 11 '07 #4

P: n/a
You are right: Placeholder works fine.
Thanks!

Greets
Ralf

"Yuriy Solodkyy" <y.************@gmail.comschrieb im Newsbeitrag
news:57***************************@msnews.microsof t.com...
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


Jun 11 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.