13 Answers, 1 is accepted

There are three ways to bind the grid to a database.
- Using declarative data source controls - By using declarative data source controls (introduced in ASP.NET 2.0), you can bind the grid declaratively, with no coding necessary.
- Using the NeedDataSource event - RadGrid calls this event each time it needs a data source.
- DataGrid-like binding - You can set the DataSource property manually in the control declaration. This property specifies the database, which is then used as a source for the grid.
Thanks,
Princy.


unable to cast type 'system.web.ui.radgrid' to 'system.web.ui.radgrid'

I am not quite sure about the requirement. Please refer to this online demo for an live example of how to bind RadGrid to a DataReader instance.
Thanks,
Princy.

I have added a radgrid and i can edit and update the data in the radgrid followed by the link buttons.
but im unable to add a new row by clicking a link button in rad grid..
the problem is when ever i click on 'new' linkbutton the previous data gets disabled

Have you set the command name property to the link button correctly?
aspx:
<
CommandItemTemplate
>
<
asp:LinkButton
runat
=
"server"
ID
=
"AddNew"
Text
=
"Add new record"
CommandName
=
"InitInsert"
>
</
asp:LinkButton
>
</
CommandItemTemplate
>
Thnaks,
Shinu.

<RadGrid>
<MasterTableView>
<EditItemTemplate>
<table>
<tr>
<td>
<Textbox> //control to bind

Thanks for ur reply.
Still it sgiving the same error.
when ever i click the link button "add" the grid get disapeared.
please give a solution for this.
i have used the following code.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="toeflUserControl.ascx.cs" Inherits="LaunchPadWebPages.UserControls.toeflUserControl" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<telerik:RadGrid ID="RadGrid2" GridLines="None" runat="server" AllowAutomaticDeletes="True"
AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" OnCancelCommand="Grid_Cancel"
AutoGenerateColumns="False" OnEditCommand="grdInvoicesStoreStyleSelected_EditCommand"
AllowMultiRowEdit="True" OnUpdateCommand="RadGrid2_UpdateCommand" OnInsertCommand="insertion">
<PagerStyle Mode="NextPrevAndNumeric" />
<MasterTableView Width="100%" EditMode="InPlace" CommandItemDisplay="Top"
HorizontalAlign="NotSet"
AutoGenerateColumns="False">
<CommandItemTemplate>
<asp:LinkButton runat="server" ID="AddNew" Text="Add new record" CommandName="InitInsert" OnClientClick="insertion">
</asp:LinkButton>
</CommandItemTemplate>
<Columns>
<telerik:GridEditCommandColumn ButtonType="LinkButton" UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="studentid" HeaderText="studentid" SortExpression="studentid"
UniqueName="studentid" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Type" HeaderText="Type" SortExpression="Type"
UniqueName="Type">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="listening" HeaderText="listening"
SortExpression="listening" UniqueName="listening">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="writing" HeaderText="writing"
SortExpression="writing" UniqueName="writing">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="reading" HeaderText="reading"
SortExpression="reading" UniqueName="reading">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Speaking" HeaderText="Speaking"
SortExpression="Speaking" UniqueName="Speaking">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CbtTotal" HeaderText="CbtTotal"
SortExpression="CbtTotal" UniqueName="CbtTotal">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PaperTotal" HeaderText="PaperTotal"
SortExpression="PaperTotal" UniqueName="PaperTotal">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="IbtTotal" HeaderText="IbtTotal"
SortExpression="IbtTotal" UniqueName="IbtTotal">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TestDate" HeaderText="TestDate"
SortExpression="TestDate" UniqueName="TestDate">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

You can try the following approach to bind the TextBox control to a datasource field in edit mode.
aspx:
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
<
asp:TextBox
ID
=
"text"
Text='<%# Bind("Name") %>'
runat="server" Visible="true"></
asp:TextBox
>
</
FormTemplate
>
</
EditFormSettings
>
Also check the following demo which discusses a similar scenario.
Grid / Form Template Edit Form.
Thanks,
Shinu.

I initially apply the results of a stored proc to the data source and bind on Page Load, then apply the two way binding '<%# Bind("text") %>' as suggested, but no data content is visiible on rendered page.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string casenbr = Request.QueryString[
"id"].ToUpper();
// get list of articles
DataSet ds = SPs.Get_Articles(casenbr).GetDataSet();
RadGrid1.DataSource = ds;
RadGrid1.DataBind();
}}
}
}
-----------------------------------------------------------------------------------------------------
<telerik:RadGrid id="RadGrid1"
runat="server"
PageSize="10"
AllowSorting="True"
AutoGenerateColumns="False"
GridLines="Both"
AllowAutomaticDeletes="True"
AllowAutomaticInserts="True"
AllowAutomaticUpdates="True"
PagerStyle-HorizontalAlign="Center"
ShowStatusBar="True"
AllowMultiRowSelection="True"
AllowMultiRowEdit="True"
OnItemInserted="RadGrid1_ItemInserted"
OnItemUpdated="RadGrid1_ItemUpdated"
OnInsertCommand="RadGrid1_ItemInsert"
OnUpdateCommand="RadGrid1_ItemUpdate"
AllowPaging="True" >
<MasterTableView DataKeyNames="CaseNbr"
EditMode="PopUp"
AutoGenerateColumns="False"
CommandItemDisplay="Top" TableLayout="Auto"
EditItemStyle-HorizontalAlign="Justify"
Caption="<br/><h2><b>Articles</b></h2>">
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"
CancelImageUrl="~/Images/filterCancel.png"
UpdateImageUrl="~/Images/selecttag.png"
InsertImageUrl="~/Images/add-icon[2].png"
EditImageUrl="~/Images/edit-icon[1].png" >
</EditColumn>
</EditFormSettings>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table>
<tr>
<td><asp:Label runat="server" ID="Label1" Text="Case Nbr:"></asp:Label></td>
<td><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CaseNbr") %>'></asp:TextBox></td>
<td><asp:Label runat="server" ID="Label5" Text="Item:"></asp:Label></td>
<td><asp:TextBox ID="TextBox13" runat="server" Text='<%# Bind("Item") %>'></asp:TextBox></td>
<td><asp:Label runat="server" ID="Label15" Text="Article:"></asp:Label></td>
<td><asp:TextBox ID="TextBox11" runat="server" Text='<%# Bind("Article") %>'></asp:TextBox></td>
<td><asp:Label runat="server" ID="Label16" Text="Entry Date:"></asp:Label></td>
<td><asp:TextBox ID="TextBox14" runat="server" Text='<%# Bind("EntryDate") %>'></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label runat="server" ID="Label17" Text="Category Code:"></asp:Label></td>
<td><asp:TextBox ID="TextBox15" runat="server" Text='<%# Bind("Category") %>'></asp:TextBox></td>
<td><asp:Label runat="server" ID="Label18" Text="Discov-By:"></asp:Label></td>
<td><asp:TextBox ID="TextBox16" runat="server" Text='<%# Bind("DiscoveredBy") %>'></asp:TextBox></td>
<td><asp:Label runat="server" ID="Label19" Text="Owner:"></asp:Label></td>
<td colspan="2"><asp:TextBox ID="TextBox17" runat="server" Text='<%# Bind("Owner") %>'></asp:TextBox></td>
</tr>
</table>
</formtemplate>
</editFormSettings>

How Can i Add a Required field validators to my Radgrid..

Check the following help documentation which explains adding validators to RadGrid.
Validation.
Thanks,
Princy.

Thanks,
JSON