5
Answers

Problem with Gridview

Peter Schmidt

Peter Schmidt

14y
8.1k
1
Hi all,

I want to develop a asp.net webapplication, but I have a big problem with the gridview and the data editing.

The data is in the gridview.
But if i press the edit-button there comes:

[HttpException (0x80004005): The GridView GridView1 RowEditing triggered the event, which was not treated.]

 System.Web.UI.WebControls.GridView.OnRowEditing(GridViewEditEventArgs e) +1321226 System.Web.UI.WebControls.GridView.HandleEdit(Int32 rowIndex) +43 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +611 System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +207 System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


But in my code i have the method.

I tried this also with vb, there it works except the update method :/. But not with c# :(((

I don't know what to do :((

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace WebApplication3
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                bingridview();

            }
        }

protected void Button1_Click(object sender, EventArgs e)
{
bingridview();
}
public void bingridview()
{
            sql = "select id,name, adress from user"
string connstr = "Data Source=*****;Initial Catalog=pwdb;Integrated Security=True";
            
SqlConnection conn = new SqlConnection(connstr);
             SqlDataAdapter sqladapter;
             SqlConnection connection;
              DataSet myds = new DataSet();
             DataSet changes = new DataSet();


SqlCommand cmd = new SqlCommand(sql, conn);
connection = new SqlConnection(connstr);

//Dim datareader As SqlDataReader
connection.Open();
sqladapter = new SqlDataAdapter(sql, connection);
//sqladapter.SelectCommand = cmd
sqladapter.Fill(myds);
connection.Close();
GridView1.DataSource = myds;
DataBind();

}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            bindGridView();
        }
      protected void GridView1_RowUpdating(object sender, GridViewEditEventArgs e)
        {
            //string val = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
        }
    }
}

 namespace WebApplication3 {
   
   
    public partial class _Default {
       
        /// <summary>
        /// form1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.HtmlControls.HtmlForm form1;
       
        /// <summary>
        /// Typ control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.TextBox ID;
       
        /// <summary>
        /// Mandant control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.TextBox name;
       
        /// <summary>
        /// SID control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.TextBox adress;

       
        /// <summary>
        /// Button1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Button Button1;
       
        /// <summary>
        /// Button2 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Button Button2;
       
        /// <summary>
        /// GridView1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.GridView GridView1;
    }
}

Screen:
c-sharp_grid.jpg

Can you please help me with the edit/update-method. I slowly begin to despair :/
Thanks a lot

Peter

Attachment: WebApplication4.rar

Answers (5)