Click here to Skip to main content
15,891,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Developers,

I am facing the following issue regarding comparing my gridview certain column data with checkboxlist item text.

I have a checkboxlist which has only 6 items.
A
B
C
D
E
F

When the gridview is populated from database and the 3rd column i-e: Cell[2].Text has the string values of A, B, C, D, E or F. Whenever it is being populated I have to disable the items of that checkboxlist which has same values like gridview cell[2].

For example if I have A, C, E, F in Gridview cell[2] then the Checkboxlist item A, C, E, F should be enable = false;

as I have created the following method for Page.Load Event.


C#
private void EditMode()
    {
        foreach(GridViewRow gvRow in GridView3.Rows)
        {
            Label userID = gvRow.Cells[2].FindControl("Label4") as Label;

            for (int k = 0; k < CheckBoxList1.Items.Count; k++)
            {
                if (CheckBoxList1.Items[k].Text == userID.Text)
                {
                    CheckBoxList1.Items[k].Enabled = false;
                }
            }
        }
    }


Please Help.. :)
Posted
Updated 12-May-14 1:11am
v2
Comments
Thanks7872 28-Oct-13 7:45am    
- If i understood correctly,if you have A in first Row,B in second row...F at 6th Row,then? Whole List would be disabled or what?
- check box list is part of a gridview or what?
AR547 28-Oct-13 7:51am    
Checkbox is out of Gridview. you are right 1st row has A, 2nd B and 3rd C so the first 3 checkboxes should be disabled in the checkboxlist control.

1 solution

C#
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowState != DataControlRowState.Edit) // check for RowState
        {
            if (e.Row.RowType == DataControlRowType.DataRow) //check for RowType
            {

                foreach (ListItem c in CheckBoxList1.Items)
                {
                    if (c.Text == userID.Text)
                    {
                        c.Enabled = false;
                    }
                }
            }
       }
    }


and to retain the checkboxes statuses whether checked or not

C#
protected void GridView3_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        DataTable dt2 = ViewState["DatainEditMode"] as DataTable;
        int index = Convert.ToInt32(e.RowIndex);
        if (dt2.Rows[index][2].ToString() == CheckBoxList1.Items[0].Text.ToString())
        {
            CheckBoxList1.Items[0].Enabled = true;
        }
        else if (dt2.Rows[index][2].ToString() == CheckBoxList1.Items[1].Text.ToString())
        {
            CheckBoxList1.Items[1].Enabled = true;
        }
        else if (dt2.Rows[index][2].ToString() == CheckBoxList1.Items[2].Text.ToString())
        {
            CheckBoxList1.Items[2].Enabled = true;
        }
        else if (dt2.Rows[index][2].ToString() == CheckBoxList1.Items[3].Text.ToString())
        {
            CheckBoxList1.Items[3].Enabled = true;
        }
        else if (dt2.Rows[index][2].ToString() == CheckBoxList1.Items[4].Text.ToString())
        {
            CheckBoxList1.Items[4].Enabled = true;
        }
        else if (dt2.Rows[index][2].ToString() == CheckBoxList1.Items[5].Text.ToString())
        {
            CheckBoxList1.Items[5].Enabled = true;
        }
        dt2.Rows[index].Delete();
        string task_no = ((Label)GridView3.Rows[e.RowIndex].FindControl("LBL_TASKNO")).Text;
        tskctrl.deleteTaskNoDetail(task_no);
        GV3DataBinding(lbl_pTask.Text.ToString());
    }
 
Share this answer
 
v2

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