我试过,但我的代码不起作用 [英] i tried but my code is not working

查看:57
本文介绍了我试过,但我的代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下





Code as follows


private void RemoveData()
    {
        DataTable dt = new DataTable();
        dt = (DataTable)ViewState["Remarks"];

        for (int irows = 0; irows < dt.Rows.Count; irows++)
        {
            if (ddlcourseuserful.SelectedItem.ToString() == "Excellent")
            {
                dt.Rows.RemoveAt(irows);
            }
        }
        ViewState["Remarks"] = dt;
        gvnegative.DataSource = dt;
        gvnegative.DataBind();
    }


  protected void btnok_Click(object sender, EventArgs e)
    {
        RemoveData();
        Pnlnegativefeedback.Visible = false;        
    }





i有一个dropdownlist1如下





参加更多课程的喜欢Dropdownlist1





当我选择上面的Drodownlist1时,mdal popup将是显示。



ModalPOPUP如下



Negative_Feed_Back

Textbox1(原因用于在该文本框中输入穷人1)

确定(按钮)



当我单击确定按钮时,选择的下拉列表和穷人的原因是在gridview中显示如下





i have one dropdownlist1 as follows


Likehood of attending more courses at insistitute Dropdownlist1


When i select the above Drodownlist1 the mdal popup will be display.

The ModalPOPUP as follows

Negative_Feed_Back
Textbox1(Reason for Typing the Poor in that Textbox1)
OK (Button)

When i click the OK Button the selected dropdown and Reason for poor is displayed in the gridview as follows

Dropdown   Reason

 0         Not Good







当我在gridview中运行时,当我选择穷人时,将显示modalpopup并给出共鸣并单击Ok(按钮) )。



在gridivew选择的下拉菜单中会显示原因。


在gridview中如下






When i run in the gridview when i select the poor and modalpopup will be displayed and give the reson and click the Ok (button).

in gridivew selected dropdown and reason will be displayed.

in the gridview as follows

Dropdown   Reason

 0         Not Good







假设用户从Dropdownlist1中选择Good的原因意味着,在gridview中的那个时间之前的价值如下






suppose user select the reason Good from the Dropdownlist1 means, that time in the gridview previously value of as follows

Dropdown   Reason

 0         Not Good





将在gridview中删除。



但我的代码无效。什么是我的代码中的问题。



问候,

Narasiman P.



will be deleted in the gridview.

But my code is not working. what is thproblem in my code.

Regards,
Narasiman P.

推荐答案

虽然我不知道你是否正在寻找问题,但我发现你的代码存在问题:



1)(否) showstopper但不必要)

DataTable dt = new DataTable();

你在这里分配一个DataTable实例,但你之后不再使用它。在下一行中,它被覆盖了

dt =(DataTable)ViewState [Remarks];

你可以把它缩短为

DataTable dt =(DataTable)ViewState [Remarks];



2)(也许是一个真正的问题)

您从零开始按行号进行迭代。您最终会根据ist数删除一行。并且你从那里进一步迭代。



在这里你必须记住你删除的行实际上已经消失了。它的行号被分配给下一个更大的行。等等。以下所有行都会向下移动一行。



由于您的迭代变量没有响应,您可能缺少要删除的行。



因此,如果您知道最多删除一行,请在删除后删除循环:
Though I don't know whether or not it is the problem you're looking for, I see a problem in your code:

1) (no showstopper but unnecessary)
DataTable dt = new DataTable();
You're assigning an instance of DataTable here, but you don't use it afterwards. In the very next line, it gets overwritten by
dt = (DataTable)ViewState["Remarks"];
You can shorten that to
DataTable dt = (DataTable)ViewState["Remarks"];

2) (Maybe a real problem)
You're Iterating by row number from zero upwards. An you're eventually deleting a row based on ist number. And you're iterating further up from there.

Here you have to keep in mind that the row you deleted is in fact gone. Its row number is assigned to the next larger row. And so on. All following rows wander one row number down.

Since your iteration variable doesn't respond to that, you may be missing a row to delete.

So, if you know that you'll delete one row at most, break the Loop after deleting:
dt.Rows.RemoveAt(irows);
break;

如果您不知道将删除多少行,请恢复循环的方向:

If you don't know how many rows will be deleted, revert the loop's direction:

for (int irows = dt.Rows.Count - 1; irows >= 0; irows--)







我不明白其余的,所以没有tipps。




I don't understand the rest, so no tipps for that.


这篇关于我试过,但我的代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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