I have a simple page where I am dynamically generating columns on the page load event and seting datasource during the need data source event. The initial load works correctly, but after any postback the columns still exist but the header text and datafield properties are empty.
Below is the simpliest example I can make. Any thoughts on why the columns are losing their information?
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public class DataClass
{
private string _a = "";
private string _b = "";
public string A { get { return this._a; } }
public string B { get { return this._b; } }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Reflection.PropertyInfo[] fields = typeof(DataClass).GetProperties();
foreach (System.Reflection.PropertyInfo field in fields)
{
GridBoundColumn c = new GridBoundColumn();
c.DataField = field.Name;
c.HeaderText = field.Name;
this.RadGrid1.MasterTableView.Columns.Add(c);
}
}
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
System.Collections.Generic.List<DataClass> results = new System.Collections.Generic.List<DataClass>();
this.RadGrid1.DataSource = results;
}
protected void Button1_Click(object sender, EventArgs e)
{
// Column exist but header text and data field properties are ""
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Force Postback" onclick="Button1_Click" />
<telerik:RadGrid ID="RadGrid1" runat="server" onneeddatasource="RadGrid1_NeedDataSource" AutoGenerateColumns="false" />
</form>
</body>
</html>

| <telerik:RadGrid ID="rgProducts" runat="server" | |
| AllowFilteringByColumn="True" DataSourceID="ldsProducts" | |
| AllowPaging="True" AllowSorting="True" Skin="Vista" PageSize="20" | |
| oncancelcommand="rgProducts_CancelCommand" Width="99%" | |
| oneditcommand="rgProducts_EditCommand" OnItemDataBound="rgProducts_ItemDataBound" | |
| onupdatecommand="rgProducts_UpdateCommand" AutoGenerateColumns="False" > | |
| <PagerStyle Height="28px" Mode="NextPrevAndNumeric" Position="Bottom"/> | |
| <mastertableview allowfilteringbycolumn="True" allowpaging="True" DataKeyNames="ProductId" | |
| allowsorting="True" TableLayout="Fixed" DataSourceID="ldsProducts"> | |
| <Columns> | |
| <telerik:GridEditCommandColumn> | |
| <HeaderStyle Width="5%" /> | |
| </telerik:GridEditCommandColumn> | |
| <telerik:GridBoundColumn DataField="ProductId" DataType="System.Int32" | |
| HeaderText="Id" ReadOnly="True" SortExpression="ProductId" | |
| UniqueName="ProductId"> | |
| <HeaderStyle Width="15%" /> | |
| </telerik:GridBoundColumn> | |
| <telerik:GridTemplateColumn HeaderText="Type" SortExpression="ProductType.ProductTypeName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True" > | |
| <ItemTemplate> | |
| <%#Eval("ProductType.ProductTypeName")%> | |
| </ItemTemplate> | |
| <HeaderStyle Width="30%" /> | |
| <ItemStyle Wrap="false" /> | |
| </telerik:GridTemplateColumn> | |
| <telerik:GridBoundColumn DataField="ProComProductCode" | |
| HeaderText="Product Code" SortExpression="ProComProductCode" | |
| UniqueName="ProComProductCode" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True"> | |
| <HeaderStyle Width="15%" /> | |
| <ItemStyle Wrap="false" /> | |
| </telerik:GridBoundColumn> | |
| <telerik:GridBoundColumn DataField="ProductName" HeaderText="Name" | |
| SortExpression="ProductName" UniqueName="ProductName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True"> | |
| <HeaderStyle Width="35%" /> | |
| <ItemStyle Wrap="false" /> | |
| </telerik:GridBoundColumn> | |
| </Columns> | |
| <editformsettings editformtype="Template"> | |
| <formtemplate> | |
| <!-- left this code out - very large --> | |
| </formtemplate> | |
| <popupsettings scrollbars="None" /> | |
| </editformsettings> | |
| </mastertableview> | |
| </telerik:RadGrid> |
I have a detail table in my grid and I want to allow paging on it but it is not working. I currently have 12 records in y dataset and I have the page size set at ten, but it will only show me the first ten records and will not show me page 2 at all. If I set the page size at 2, the detail table will show only 2 records and will not page to any other page. If I set the pagesize to 20 it will show all 12 records, but then I will only be able to see the first 20 records. Basically it is not allowing me to see past the first page in the detail table.
Does anyone know what would be causing this behavior? What would be the correct pager settings for both the master table and the detail tables?
| <li class="selector"> |
| <asp:Label ID="Label12" AssociatedControlID="Image2" runat="server"> |
| <asp:Literal ID="Literal14" runat="server" Text="IMAGE2"></asp:Literal> |
| <em id="Em5" runat="server"></em></asp:Label> |
| <asp:TextBox ID="Image2" Text="" runat="server" MaxLength="250"></asp:TextBox> |
| <im:ImageCaller ID="ImageCaller2" runat="server" /> |
| <p class="example"> |
| <asp:Literal ID="Literal15" runat="server" Text="Using Image Manager"></asp:Literal></p> |
| </li> |