I am using Essetial Object grid in one of the webappliction i tried the following C# code.. but could able to bind the data in EO.grid view but unable to save the data ( edited in the grid ) into the data base..
Please help me out in finding the solution for this..
------------
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;
using EO.Web;
using EO.Web.Internal;
public partial class _Default : System.Web.UI.Page
{
public static string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\mshamanna\My Documents\Visual Studio 2010\WebSites\EOTest2\App_Data\Database.mdf;Integrated Security=True;User Instance=True";
protected void Page_Load(object sender, System.EventArgs e)
{
string sql = @"select * from Temp";
SqlConnection conn = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(sql, conn);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "Temp");
Grid1.DataSource = ds.Tables[0];
Grid1.DataBind();
}
//To Save grid values into database
protected void btnSave_Click(object sender, System.EventArgs e)
{
string header3 = "";
int id = 0;
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
int count = 0;
foreach (EO.Web.GridItem item in Grid 1.Items)
{
count++;
//Get the cell value in the second column
header3 = (string)item.Cells[2].Value;
string sql = @"UPDATE TEMP SET HEADER3='" + header3 + "' WHERE ID='" + count + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
conn.Close()
}
---------------------
swamy smPosted Feb 21, 2011, 7:03 AM
As per my requirement, I am able to bind the data but i am getting NULL values being saved in the SQL database..
Could you help in retriving grid cell value and save it into the database..
Thanks a ton for your reply
Swamy
Krishna GaradPosted Feb 21, 2011, 6:41 AM
page_load
{
if(!IsPostBack)
{
//Bind Grid here
}
}
then it will update the record and why you are using btnsave it will provide update button also after edit in that updating event write you update code. It may help you.