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" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<asp:GridView AllowPaging="True" AllowSorting="True" ID="GridView1" runat="server" BackColor="White" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="1px" CellPadding="3" PageSize="5" ForeColor="Black" GridLines="Vertical" AutoGenerateEditButton="false" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="intmsgID" OnPageIndexChanging="GridView1_PageIndexChanging1" OnRowCancelingEdit="GridView1_RowCancelingEdit1" OnRowEditing="GridView1_RowEditing1" OnRowUpdating="GridView1_RowUpdating" >
<FooterStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowEditButton="True" ButtonType="Button"></asp:CommandField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ReadOnly="True" />
<asp:BoundField DataField="txtmsg" HeaderText="Message" SortExpression="txtmsg" />
<%-- <ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"txtmsg") %>
</ItemTemplate>--%>
<%--<asp:TemplateField HeaderText="message" SortExpression="txtmsgs">
<EditItemTemplate>
<asp:TextBox ID="txtmsg" runat="server" Text='<%# eval("strmsg") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="message" SortExpression="txtmsg">
<EditItemTemplate>
<asp:TextBox Text='<%# DataBinder.Eval(Container.DataItem,"txtmsg") %>' ID="txtmsg" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testareaConnectionString %>"
SelectCommand="SELECT tbllog.UserID, tblMSG.intmsgID, tbllog.Name, tblMSG.txtmsg FROM tbllog INNER JOIN tblMSG ON tbllog.UserID = tblMSG.intuserID and tblMSG.intmsgID = @intmsgID"
UpdateCommand="UPDATE tblMSG SET tblMSG.txtmsg = @txtmsg WHERE (tblMSG.intmsgID = @msgid)" >
<UpdateParameters>
<asp:Parameter Name="txtmsg" Type="string"/>
<asp:Parameter Name="intmsgID" Type="int64" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="msgid" QueryStringField="msgid" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
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)
{
}
}