Hi all,
I am new to this,i have created a grid view to display all the msg and it is like name, msgid, msg,date. here i have to update only the msg. i have got name from table registration and msgid and msg from table msg. i am able to create that edit button. But on clicking update button it is not getting updated and is retaining its previous value. Plz help me. Its very important for me.here is my code. thank u,
<%@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true" CodeFile="griddisp.aspx.cs" Inherits="griddisp" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml" >
and code behind is,
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class griddisp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//if (!this.IsPostBack)
//{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConToDb"].ToString().Trim());
SqlCommand sqlcom = new SqlCommand("SPDisplaymsgs");
sqlcom.Connection = sqlcon;
sqlcon.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlcom;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataSourceID = null;
GridView1.DataBind();
//}
}
protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
DataBind();
}
protected void GridView1_RowCancelingEdit1(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
DataBind();
}
////protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
////{
//// GridView1.EditIndex = e.NewValues.ToString();
//// GridView1.UpdateRow;
//// DataBind();
////}
//protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
//{
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
}
}
Bechir BejaouiPosted Dec 1, 2008, 1:06 PM
vinay uthappaPosted Dec 1, 2008, 6:30 AM
vinay uthappaPosted Dec 1, 2008, 5:40 AM
Bechir BejaouiPosted Dec 1, 2008, 5:21 AM
//if (!this.IsPostBack)
//{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConToDb"].ToString().Trim());
SqlCommand sqlcom = new SqlCommand("SPDisplaymsgs");
sqlcom.Connection = sqlcon;
sqlcon.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlcom;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataSourceID = null;
GridView1.DataBind();
but you want that when the page content is posted then the update is automatically done//}
I'm not sure but try this alternative
write a HTTPHandler class
public class UpdateHandler: IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConToDb"].ToString().Trim());
SqlCommand sqlcom = new SqlCommand("SPDisplaymsgs");
sqlcom.Connection = sqlcon;
sqlcon.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlcom;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataSourceID = null;
GridView1.DataBind();
context.Response.Write("
Operation is done
");
}
public bool IsReusable{get{return true;}}
}
then you configure your configuration file so that foreach post the code is leveraged
Of Corse, the button has to have configured to send post request
Mansi ShahPosted Dec 1, 2008, 4:56 AM
if (!Page.IsPostBack)
{ }