This is a migrated thread and some comments may be shown as answers.

RadGrid DataBind error

3 Answers 256 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jared
Top achievements
Rank 1
Jared asked on 04 Jan 2011, 02:49 PM
Ok, I am using the radgrid to databind to a DataTable and it isn't updating any of the data when the edit form update button is pressed. From what I understand I need to rebind the data when the update button is pressed, however when I do that I am left with an empty grid.
Page load code:
 if (!IsPostBack)
   {
       
       DataTable dt = new DataTable();
       dt.Columns.Add("User");
       dt.Columns.Add("Comment");
       DataRow dr = dt.NewRow();
       dr["User"] = "Name";
       dr["Comment"] = "This is a comment";
       dt.Rows.Add(dr);
       Session.Add("dt", dt);
       RadGridComments.DataSource = dt;
       RadGridComments.DataBind();
   
   }
RadGrid:
<telerik:RadGrid ID="RadGridComments" runat="server" AllowFilteringByColumn="True" 
        AllowPaging="True" GridLines="None" EnableAjax="true" 
        AllowAutomaticUpdates="True" 
        oneditcommand="RadGridComments_EditCommand" 
        AutoGenerateEditColumn="True" >
        <MasterTableView AllowAutomaticUpdates="True">
        </MasterTableView>
</telerik:RadGrid>
and the edit command:
 protected void RadGridComments_EditCommand(object sender, GridCommandEventArgs e)
  {
      RadGridComments.DataSource = (DataTable)Session["dt"];
      RadGridComments.Rebind();
  }
now I want to specify that I am not able to use a SQL database with this project and I am having some problems making my datasource persistent.  I am going to be loading content from a website and filling out the radgrid, then when the edit command fires I need to push the info to the website(and then pull and rebind I assume).  I am unable to get my simple test code here working and I would appreciate your help.  So how do I set the new info from the edit form to my datatable? when using SQL databases it felt like this was done for me.

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 04 Jan 2011, 03:26 PM
Hello Jared,

Note that simple data-binding through the DataBind() method can be used in simple scenarios which does not require complex operations like insert/delete/update, grouping, hierarchy relations, etc.
Please try reworking the code to use only Advanced databinding vs Simple databinding and let me know how it goes.

All the best,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jared
Top achievements
Rank 1
answered on 04 Jan 2011, 03:44 PM
Actually in this example I need it to be able to edit.  I was trying to create a small scale example of editing data in a dataTable without connecting to an SQL database(static table for the example).  However, when I execute the Edit button it gives me an empty grid.
0
Pavlina
Telerik team
answered on 04 Jan 2011, 04:38 PM
Hi Jared,

To resolve this problem you should remove any DataBind() calls and configure the binding of your grid merely by means of NeedDataSource event handling.

More information on this subject can be found below:
http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Jared
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Jared
Top achievements
Rank 1
Share this question
or