I created a RadGrid with predefined columns. At first when I ran the webpage, the grid was blank, not even showing the headers. But by creating a blank dataset in a Session variable and assigning it to the RadGrid, I get it to display. However, the "Add Record", "Edit", and "Delete" buttons don't work.
The online demos are all bound to a datasource, but we don't want that. How can the RadGrid work with a dataset in memory? I want the MasterTableView to load and display values, which I'll save later, all at once. My dummy HTML and code-behind are below...
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> |
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> |
<!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> |
</head> |
<body> |
<form id="form1" runat="server"> |
<div> |
<asp:ScriptManager ID="ScriptManager1" runat="server"> |
</asp:ScriptManager> |
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None" |
AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"> |
<HeaderContextMenu EnableAutoScroll="True"> |
</HeaderContextMenu> |
<MasterTableView CommandItemDisplay="Top"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridBoundColumn DataField="Col1" HeaderText="Col1" UniqueName="Col1" SortExpression="Col1"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Col2" HeaderText="Col2" UniqueName="Col2" SortExpression="Col2"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
</div> |
</form> |
</body> |
</html> |
Imports System.Data |
Partial Class _Default |
Inherits System.Web.UI.Page |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
If Not IsPostBack Then |
Dim ds As New DataSet |
Dim dt As New DataTable |
dt.Columns.Add("Col1") |
dt.Columns.Add("Col2") |
' Create dummy rows to delete/edit |
Dim vals(1) As String |
vals = New String() {"100", "Desc100"} |
dt.Rows.Add(vals) |
vals = New String() {"200", "Desc200"} |
dt.Rows.Add(vals) |
ds.Tables.Add(dt) |
Session("myDS") = ds |
RadGrid1.DataSource = Session("myDS") |
RadGrid1.MasterTableView.DataSource = Session("myDS") |
End If |
End Sub |
End Class |