I am trying to learn the basics of Telerik's RadGrid.
I am trying to place an empty grid on a page with just column headers. With the following code, just an empty, white rectangle appears instead.
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Windows7" >
<MasterTableView>
<Columns>
<telerik:GridBoundColumn HeaderText="TextTitle" HeaderButtonType="TextButton" UniqueName="NamePINcolumn" />
</Columns>
</MasterTableView>
Currently I don't have any data to supply the table, I just want to hard code some data into the table for demo purposes. Is this possible?
You need DataField for GridBoundColumn. Otherwise, Grid doesn't know what field to display.
<telerik:GridBoundColumn DataField="xxx " ... />
<telerik:RadGrid runat="server" ID="RadGrid1"
AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource">
<mastertableview datakeynames="Id">
<Columns>
<telerik:GridBoundColumn DataField="Id"
UniqueName="Id" HeaderText="Id"/>
<telerik:GridBoundColumn DataField="Name"
UniqueName="Name" HeaderText="Name"/>
</Columns>
</mastertableview>
</telerik:RadGrid>
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}
public partial class WebForm1 : System.Web.UI.Page
{
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
var users = new List<Customer>
{
new Customer {Id = 1, Name = "Jon"},
new Customer {Id = 2, Name = "Marry"}
};
RadGrid1.DataSource = users;
}
}