Have been working on the code to update a GridView in Visual Studio 2005. Have the AutogeneratedEditButton set to true. When I run it nothing happens doesnt give me any error but is not updating.
In the aspx page I have a the the following code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Edit1.ascx.cs" Inherits="CMSWebParts_MyWebParts_Edit1" %>
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit" onrowupdating="GridView1_RowUpdating" onrowdeleting="GridView1_RowDeleting"
AutoGenerateEditButton="True" AutoGenerateSelectButton="True" AllowPaging="True" Width="625px" Height="295px">
</asp:GridView>
And in the cs page:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings["Data Source=CORPEUEIS1;Initial Catalog=PSCEMEAWEB_B;User ID=PSCEMEA_DBO;Password=PSCEMEA_DBO"].ConnectionString;
string strProvider = ConfigurationManager.ConnectionStrings["System.Data.SqlClient"].ProviderName;
string selectCommand = "Select FAQ1ID, FormInserted, Area, Topic, Issue, Update1 from TBL_FAQ1 where Area = 'CXP' order by FAQ1ID asc";
SqlDataSource ds = new SqlDataSource(strProvider, strConn, selectCommand);
ds.ID = "FAQ1ID";
ds.UpdateCommand = "UPDATE TBL_FAQ1 SET FormInserted = @FormInserted, Area = @Area, Topic = @Topic, Issue = @Issue, [Update1] = @Update1 WHERE (FAQ1ID = @FAQ1ID)";
Parameter FormInserted = new Parameter("FormInserted", TypeCode.String);
Parameter Area = new Parameter("Area", TypeCode.String);
Parameter Topic = new Parameter("Topic", TypeCode.String);
Parameter Issue = new Parameter("Issue", TypeCode.String);
Parameter Update1 = new Parameter("Update1", TypeCode.String);
ds.UpdateParameters.Add(FormInserted);
ds.UpdateParameters.Add(Area);
ds.UpdateParameters.Add(Topic);
ds.UpdateParameters.Add(Issue);
ds.UpdateParameters.Add(Update1);
Page.Controls.Add(ds);
SqlDataSource m_SqlDataSource = Page.FindControl("FAQ1ID") as SqlDataSource;
if (m_SqlDataSource != null)
{
this.GridView1.DataSourceID = m_SqlDataSource.ID;
}
BindData();
GridView1.EditIndex = -1;
}
Thanks in advance
In the aspx page I have a the the following code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Edit1.ascx.cs" Inherits="CMSWebParts_MyWebParts_Edit1" %>
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit" onrowupdating="GridView1_RowUpdating" onrowdeleting="GridView1_RowDeleting"
AutoGenerateEditButton="True" AutoGenerateSelectButton="True" AllowPaging="True" Width="625px" Height="295px">
</asp:GridView>
And in the cs page:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings["Data Source=CORPEUEIS1;Initial Catalog=PSCEMEAWEB_B;User ID=PSCEMEA_DBO;Password=PSCEMEA_DBO"].ConnectionString;
string strProvider = ConfigurationManager.ConnectionStrings["System.Data.SqlClient"].ProviderName;
string selectCommand = "Select FAQ1ID, FormInserted, Area, Topic, Issue, Update1 from TBL_FAQ1 where Area = 'CXP' order by FAQ1ID asc";
SqlDataSource ds = new SqlDataSource(strProvider, strConn, selectCommand);
ds.ID = "FAQ1ID";
ds.UpdateCommand = "UPDATE TBL_FAQ1 SET FormInserted = @FormInserted, Area = @Area, Topic = @Topic, Issue = @Issue, [Update1] = @Update1 WHERE (FAQ1ID = @FAQ1ID)";
Parameter FormInserted = new Parameter("FormInserted", TypeCode.String);
Parameter Area = new Parameter("Area", TypeCode.String);
Parameter Topic = new Parameter("Topic", TypeCode.String);
Parameter Issue = new Parameter("Issue", TypeCode.String);
Parameter Update1 = new Parameter("Update1", TypeCode.String);
ds.UpdateParameters.Add(FormInserted);
ds.UpdateParameters.Add(Area);
ds.UpdateParameters.Add(Topic);
ds.UpdateParameters.Add(Issue);
ds.UpdateParameters.Add(Update1);
Page.Controls.Add(ds);
SqlDataSource m_SqlDataSource = Page.FindControl("FAQ1ID") as SqlDataSource;
if (m_SqlDataSource != null)
{
this.GridView1.DataSourceID = m_SqlDataSource.ID;
}
BindData();
GridView1.EditIndex = -1;
}
Thanks in advance