Hi,
I have a case where I don't know which columns that should be generated for a grid until I am in NeedDataSource.
Then I tried to add the columns in that event. I would really like to use the built in EnableColumnViewState since that simplifies a lot, but the problem is that some (most?) properties are lost on postback, for example the HeaderText of the column in the following sample:
From what I can see in your source code it should work, but it doesn't, or am I missing something?
Regards
Caesar
I have a case where I don't know which columns that should be generated for a grid until I am in NeedDataSource.
Then I tried to add the columns in that event. I would really like to use the built in EnableColumnViewState since that simplifies a lot, but the problem is that some (most?) properties are lost on postback, for example the HeaderText of the column in the following sample:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication4.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
script
runat
=
"server"
>
Sub rg_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rg.NeedDataSource
rg.Columns.Clear()
Dim col As New Telerik.Web.UI.GridBoundColumn()
col.DataField = "Col2"
col.HeaderText = "My header text"
rg.Columns.Add(col)
Dim dt As New System.Data.DataTable()
dt.Columns.Add("Col1", GetType(String))
dt.Columns.Add("Col2", GetType(String))
For i As Integer = 0 To 10
dt.Rows.Add({"Row" & i, "Data"})
Next
rg.DataSource = dt
End Sub
</
script
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
ID
=
"ScriptManager"
runat
=
"server"
>
</
asp:ScriptManager
>
<
div
>
<
telerik:RadGrid
ID
=
"rg"
runat
=
"server"
AutoGenerateColumns
=
"false"
>
</
telerik:RadGrid
>
<
asp:Button
ID
=
"aaa"
runat
=
"server"
Text
=
"Postback"
/>
</
div
>
</
form
>
</
body
>
</
html
>
From what I can see in your source code it should work, but it doesn't, or am I missing something?
Regards
Caesar