This is a migrated thread and some comments may be shown as answers.

Grid in user control - loses column headers on postback

1 Answer 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leather
Top achievements
Rank 1
Leather asked on 15 Jul 2008, 03:28 PM
Hi There,

I am new to using your components but I have run into a problem that I can't find a way around.

I am trying to wrap the grid into a user control so that we can just set some basic properties and have it load the data (IE a sql statement). When I do this the grid works fine but if any kind of postback occurs the grid loses the column captions. The only unusual thing I am doing is that I have a property on my user control that allows columns to be specified in the ASPX file, these are then added to the rad grid:

<uc1:Grid ID="Grid1" runat="server" SQL="SELECT * FROM v_Requirement_AllFields" >

<Columns>

<telerik:GridHyperLinkColumn DataNavigateUrlFields="Requirement_RequirementId" DataNavigateUrlFormatString="ViewRequirement.aspx?RequirementId={0}" HeaderText="Reference" DataTextField="Requirement_RequirementReference"></telerik:GridHyperLinkColumn>

</Columns>

</uc1:Grid>


The code in my user control is very simple, basically as follows:

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

For Each col As GridColumn In Columns

telerikGrid.Columns.Add(col)

Next

End If

End Sub

Protected Sub telerikGrid_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles telerikGrid.NeedDataSource

If Not String.IsNullOrEmpty(_sql) Then

telerikGrid.DataSource = GetDataStore(

Me.Page).GetDataTable(_sql)

End If

End Sub

I have tried this with both Ajax enabled or disabled.

Any ideas?

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 16 Jul 2008, 05:18 AM
Hello Leather,

When the grid is declared on the page and only grid columns are created programatically you should add the column immediately in the columns collection before accessing any column properties. Scenarios where part of the columns are declared and part of the columns are created programatically are not supported.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Leather
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or