Hi,
I can easily bind the grid to a List<> collection on Page_Load. However, I'm unable to populate the grid with data on an postback from an user event - for example a button click, and I can't really understand why.
Below is a sample of what I'm trying to do - the result should be the three random rows inserted into the grid, but the grid remains empty. I also can provide a small project sample, but I can't attach it to the post - you only accept gif, jpg files?
ASPX:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApplication1.test" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <telerik:RadButton ID="RadButton1" runat="server" Text="Load" onclick="RadButton1_Click"> </telerik:RadButton> <telerik:RadGrid Width="400px" Height="400px" ID="RadGrid1" runat="server"> </telerik:RadGrid></asp:Content>Code behind:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace WebApplication1{ public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadButton1_Click(object sender, EventArgs e) { List<FillTest> testList = new List<FillTest>(); testList.Add(new FillTest("wer", "ERterte", "ertert", "ertert")); testList.Add(new FillTest("ertert", "dfgdfg", "ertert", "ertert")); testList.Add(new FillTest("dgdfg", "rwer", "pfsd", "vfswe")); RadGrid1.DataSource = testList; } } public class FillTest { string _testProperty, _test, _description, _code; public string Code { get { return _code; } set { _code = value; } } public string Test { get { return _test; } set { _test = value; } } public string Description { get { return _description; } set { _description = value; } } public string TestProperty { get { return _testProperty; } set { _testProperty = value; } } public FillTest(string testProperty, string test, string description, string code) { _testProperty = testProperty; _test = test; _description = description; _code = code; } }}