Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code as follows


C#
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 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



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



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


will be deleted in the gridview.

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

Regards,
Narasiman P.
Posted
v2

1 solution

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:
C#
dt.Rows.RemoveAt(irows);
break;
If you don't know how many rows will be deleted, revert the loop's direction:
C#
for (int irows = dt.Rows.Count - 1; irows >= 0; irows--)



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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900