I'm trying to do some error handling on a column to see if it's not equal to a certain word. I'm wondering though do i do this on the RowUpdating event or the RowUpdated event. I've been trying to do this in the rowupdating event and haven't had any luck so far. Here's the code.

      TableCell cell = GridView1.Rows[e.RowIndex].Cells[3];

        if(cell.Text == "hello")
        {
            e.Cancel = true;
        }
        lblError.Text = "hello" + cell.Text;

I assume the 3 after inside the brackets after .Cells is the column index that I want. If i use .Cells[1] it will show the primary key no in the label, but if I try 2 or 3 nothing seems to be getting placed inside the cell variable. My table has four columns, ID, Name, Price, and CategoryID. Any help is appreciated.

有帮助吗?

解决方案

If you are trying to get the input box values, you will have to find the control like:

GridViewRow row = GridView1.Rows[e.RowIndex];
string price = ((TextBox)(row.Cells[3].Controls[0])).Text;

You can also check against the e.NewValues.

And fyi: You will have to set the e.Cancel=true, if you want to cancel the event upon meeting certain condition(s).

Check RowUpdatingEvent ref.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top