在GridView'触发的事件RowUpdating这是不处理的。 C#$ C $背后asp.netÇ [英] The GridView ' ' fired event RowUpdating which wasn't handled. C# code behind asp.net

查看:172
本文介绍了在GridView'触发的事件RowUpdating这是不处理的。 C#$ C $背后asp.netÇ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有#2和其他网站类似的问题,但我似乎错过的东西。

There are similar questions on Stackoverflow and other websites, but I seem to miss something.

我有一个绑定到来自数据库的DataTable的GridView。我的目标是在与一个按钮,这是调用follwing方法相同的行中的时间更新的一行。

I have a GridView bound to a DataTable which comes from a database. My goal is to update the one row at the time with a button which is in the same row which calls the follwing Method.

        protected void TestsToBeDone_RowUpdating(object sender, GridViewEditEventArgs e)
    {
        SqlConnection myConnection = getConnection();
        myConnection.Open();

        int index = Convert.ToInt32(e.NewEditIndex);

        GridViewRow selectedRow = TestsToBeDone.Rows[index];
        TableCell LABAVIDc = selectedRow.Cells[1];
        int LABAVID = Convert.ToInt32(LABAVIDc.Text);

        TableCell assistentc = selectedRow.Cells[5];

        string query = "UPDATE Labaanvraag " +
                       "SET Status='4' "+
                                 "WHERE LABAVID ='"+LABAVID+"'";
        }

        SqlCommand commandZ = new SqlCommand(query, myConnection);
        commandZ.ExecuteNonQuery();            

        myConnection.Close();

        SetPatientTestGrid(Session["PATID"], e);
    }

它被从这里叫:

    <asp:GridView ID="TestsToBeDone" runat="server" EnableModelValidation="True" OnRowEditing="TestsToBeDone_RowUpdating">
    <Columns>
        <asp:ButtonField ButtonType="Button" CommandName="Update" 
            HeaderText="Afgenomen" ShowHeader="True" Text="Afgenomen" />
    </Columns>
</asp:GridView>

在我第一次尝试我有一个OnRowCommand与在code后面的GridViewCommandEventArgs。

At my first try I had a OnRowCommand with the GridViewCommandEventArgs at the code behind.

但它仍然抛出同样的异常,虽然我的一对夫妇的网站,它更改为OnRowEditing和GridViewEditEventArgs可以解决这个问题读取。

But it still throws the same exception, although I've read on a couple of sites that changing it to OnRowEditing and GridViewEditEventArgs would solve the problem.

由于提前,

推荐答案

GridView的ASP.NET中有一些内置的命令 - 删除更新等发生了什么事是你的按钮有更新的命令名称,并在GridView的劫持,从你和发射 RowUpdating 事件,而不是你的 RowEditing 事件。更改按钮命令名称为修改,并使用 RowEditing 事件。

GridView's in ASP.NET have some built in commands - Deleted, Update, etc. What's happening is that your button has a command name of Update, and the Gridview is hijacking that from you and firing a RowUpdating event instead of your RowEditing event. Change your button command name to be Edit, and use a RowEditing event.

这篇关于在GridView'触发的事件RowUpdating这是不处理的。 C#$ C $背后asp.netÇ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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