单击时网格视图编辑或删除选项 [英] Grid view edit or delete option on click

查看:61
本文介绍了单击时网格视图编辑或删除选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除或更新网格视图中的数据点击bt此代码(如下)给出错误plzz告诉我这段代码有什么问题..plzz.Thnxzz ..





此代码中显示的错误是......当点击删除时..GridView'GridView1'触发了未处理的事件RowDeleting。



此代码中显示的错误是......单击编辑时..GridView'GridView1'触发了未处理的事件RowEditing。









code

  protected   void  Page_Load( object  sender,EventArgs e)
{
conn = new SqlConnection( 数据源= DEEPAK-PC\\SQLEXPRESS;初始目录= NewCrackers; uid = sa; pwd = sasa;);
if (!IsPostBack)
{
bind();
}
}
受保护 void GridView1_RowEditing( object sender,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowCancelingEdit( object sender,GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
受保护 void GridView1_RowUpdating( object sender,GridViewUpdateEventArgs e)
{
GridViewRow row =(GridViewRow)GridView1.Rows [e.RowIndex];
Label lbl =(Label)row.FindControl( lblid);
TextBox textname =(TextBox)row.FindControl( textbox1);
TextBox textmarks =(TextBox)row.FindControl( textbox2);

GridView1.EditIndex = -1;
conn.Open();
SqlCommand cmd = new SqlCommand( update \\ temp set marks = + textmarks.Text + ,name =' + textname .Text + '其中rowid = + lbl.Text + ,conn);
cmd.ExecuteNonQuery();
conn.Close();
bind();
}
public void bind()
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter( select *来自emp,conn);
DataSet ds = new DataSet();
da.Fill(ds, emp);
GridView1.DataSource = ds.Tables [ 0 ];
GridView1.DataBind();
conn.Close();
}
受保护 void GridView1_RowDeleting( object sender,GridViewDeleteEventArgs e)
{
GridViewRow row =(GridViewRow)GridView1.Rows [e.RowIndex];
标签lbldeleteID =(标签)row.FindControl( lblid);
conn.Open();
SqlCommand cmd = new SqlCommand( delete emp其中rowid = + lbldeleteID.Text + ,conn);
cmd.ExecuteNonQuery();
conn.Close();
bind();
}
protected void GridView1_PageIndexChanging( object sender,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bind();
}

解决方案

确保您的ASPX Gridview有这些信息..



 <   asp:GridView     ID   =  GridView1    runat   =  server  
onrowdeleting = GridView1_RowDeleting
onrowediting = GridView1_RowEditing
onpageindexchanging <跨度class =code-keyword> = GridView1_PageIndexChanging
onrowcancelingedit = GridView1_RowCancelingEdit
onrowupdating = GridView1_RowUpdating

>





可能的修复



  • 它可能与其他名称一样,如GridView1_RowDeleting_1等。请检查事件名称
  • 如果它是aleady在那里,删除相同并为上面两个创建一个新事件并将其映射到事件背后的代码......


HI

请参考此链接可能会对您有所帮助





http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/

Hii i m trying to delete or update data in grid view on click bt this code(below) gives an error plzz tell me what is wrong in this code..plzz.Thnxzz..


Error showing in this code is...when click delete..""The GridView 'GridView1' fired event RowDeleting which wasn't handled.""

Error showing in this code is...when click edit..""The GridView 'GridView1' fired event RowEditing which wasn't handled."""




code

protected void Page_Load(object sender, EventArgs e)
    {
        conn = new SqlConnection("Data Source=DEEPAK-PC\\SQLEXPRESS;Initial Catalog=NewCrackers;uid=sa;pwd=sasa;");
        if (!IsPostBack)
        {
            bind();
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        Label lbl = (Label)row.FindControl("lblid");
        TextBox textname = (TextBox)row.FindControl("textbox1");
        TextBox textmarks = (TextBox)row.FindControl("textbox2");

        GridView1.EditIndex = -1;
        conn.Open();
        SqlCommand cmd = new SqlCommand("update  emp set marks=" + textmarks.Text + " , name='" + textname.Text + "' where rowid=" + lbl.Text + "", conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        bind();
    }
    public void bind()
    {
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter("select * from emp", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "emp");
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        conn.Close();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
 GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
 Label lbldeleteID = (Label)row.FindControl("lblid");
 conn.Open();
 SqlCommand cmd = new SqlCommand("delete  emp where rowid=" + lbldeleteID.Text + "", conn);
 cmd.ExecuteNonQuery();
conn.Close();
bind();
}
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        bind();
    }

解决方案

Make sure that your ASPX Gridview has this information..

<asp:GridView ID="GridView1" runat="server"
        onrowdeleting="GridView1_RowDeleting"
        onrowediting="GridView1_RowEditing"
        onpageindexchanging="GridView1_PageIndexChanging"
        onrowcancelingedit="GridView1_RowCancelingEdit"
        onrowupdating="GridView1_RowUpdating" 
        >



Possible fix :


  • it might be with some other name like GridView1_RowDeleting_1 etc. Pls check the event names
  • if it is aleady there ,delete the same and create a new event for the above two and map it to the code behind event...


HI
Please refer this link may it will help you


http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/


这篇关于单击时网格视图编辑或删除选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆