Click here to Skip to main content
12,075,066 members (66,576 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C ASP.NET
Hello,
i have a checkbox in my gried view .
based on the value from my list i have to chekc or uncheck the checkbox.
as i have value like 1 or o if 1 the check or else uncheck. but its not working .
Please help.
List<user> lstusers = new List<user>();
            objDetails = new Details();
            lstusers = objDetails.getAllUsers();
            grdUserList.DataSource = lstusers;
            grdUserList.DataBind();
            foreach (GridViewRow row in grdUserList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chk = new CheckBox();
                    chk = (CheckBox)row.FindControl("chkIsEnbled");
                    for (int i = 0; i < lstusers.Count; i++)
                    {
                        if (lstusers[i].isEnable == "1")
                        //if (row.Cells[5].Text == "1")
                        {
                            chk.Checked = true;
                        }
                        else
                        {
                            chk.Checked = false;
                        }
                    }
                }
            }</user>
Posted 1-Oct-12 2:56am
Edited 1-Oct-12 2:58am
JF201554.3K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

You need to debug and check the value of lstusers[i].isEnable at run time. Is it "1" or some thing different like "true" or any other string?
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I think problem is with your following if condition
if (lstusers[i].isEnable == "1")
rest of the code seems to be ok.
Debug and check value of lstusers[i].isEnable at run time.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100