Kartik Patel
Kartik Patel

Reputation: 9623

I want to delete row in repeater

I have code like this

    protected void rptCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRow dr = ((DataRowView)e.Item.DataItem).Row;
            LinkButton lnkcoursename = (LinkButton)e.Item.FindControl("lnkCategory");
             Label lblcount = (Label)e.Item.FindControl("lblCount");
            string k = lnkcoursename.CommandArgument.ToString();
            if (k != "0")
            {
                TrainingCourse traningCourse = new TrainingCourse();
                int count = traningCourse.CourseCount(Convert.ToInt32(k), "", "");
                if (count == 0)
                {
                    //This code is not working
                    dr.Delete();
                    dr.AcceptChanges();
                }
                else
                {
                    lblcount.Text = "(" + count + ")";
                }
            }
    }

Now my question is if I found count = 0 then I want to delete that row from repeater. I dont want to delete it from database and then rebind it......

Upvotes: 3

Views: 10920

Answers (1)

asktomsk
asktomsk

Reputation: 2298

You tries to delete a row associated with data source. But for this task much better to just hiding the item:

e.Item.Visible = false

Upvotes: 13

Related Questions