Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 4th, 2005, 02:34 AM
Authorized User
 
Join Date: May 2005
Location: pune, maharashtra, India.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot implicitly convert type int to bool

Hi Friends,
i would like your help as i am getting some problems with the following code.
i have marked the lines in red color.
please help me out.

private void btnauthor_Click(object sender, System.EventArgs e)
{
    int i;
    CheckBox cb;
    DataGridItem dgitem;
    for(i=0;dgemp.Items.Count-1;i++)
    {
         dgitem= dgemp.Items[i];
         cb=(CheckBox)(dgitem.FindControl("chk1"));
    }
    if(cb ="" && cb.Checked )
    {
        ordList += dgitem.Cells[1].Text + "";
    }
    lblexec.Text= KillEnding(ordList.Trim());
}

private string KillEnding(string sItem)
{
    return sItem.Substring(0,sItem.Length-1);
}



Reply With Quote
  #2 (permalink)  
Old May 4th, 2005, 04:32 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

You are assigning cb="" and checking.That is the problem.Check with == operator instead of =

Reply With Quote
  #3 (permalink)  
Old May 4th, 2005, 05:13 AM
Authorized User
 
Join Date: May 2005
Location: pune, maharashtra, India.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks...
but i need to know about the first problem also....ie for loop one...

Regards,
muskaan

Reply With Quote
  #4 (permalink)  
Old May 4th, 2005, 05:23 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Hi u didnt mention the condition for it
for(i=0;i > dgemp.Items.Count-1;i++)


Reply With Quote
  #5 (permalink)  
Old May 4th, 2005, 05:40 AM
Authorized User
 
Join Date: May 2005
Location: pune, maharashtra, India.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
i am still getting error for...
  if(cb ="" && cb.Checked )
and the error is : operator == cannot be applied to the operands of the type "system.web.ui.webcontrols.checkbox" and "string"

Thanks & Regards,
Muskaan.

Reply With Quote
  #6 (permalink)  
Old May 4th, 2005, 05:47 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

cb is an object..Check for null and cb.Checked

Reply With Quote
  #7 (permalink)  
Old May 4th, 2005, 06:18 AM
Authorized User
 
Join Date: May 2005
Location: pune, maharashtra, India.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
please let me tell you the details.

I am trying to display checkboxes in the datagrid.

In this program, I have done the coding for “Select All” and “Clear All” buttons but I am getting error for “GetEmployeeIDs” button.



The code is as follows:



private void btnauthor_Click(object sender, System.EventArgs e)

            {

                  int i;

                  CheckBox cb;

                  DataGridItem dgitem;

                  for(i=0;dgemp.Items.Count-1;i++)
                  {

                         dgitem= dgemp.Items[i];

                         cb=(CheckBox)(dgitem.FindControl("chk1"));

                  }

                  if(cb ==null && cb.Checked )
                  {

                        ordList += dgitem.Cells[1].Text + "";

                  }

                  lblexec.Text= KillEnding(ordList.Trim());

            }



            private string KillEnding(string sItem)

            {

                  return sItem.Substring(0,sItem.Length-1);

            }

 now, i am getting runtime error and that is : object reference not set to an instance of the object.

Thanks & Regards,

Muskaan.





Reply With Quote
  #8 (permalink)  
Old May 4th, 2005, 06:48 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You might run into problems with this

if(cb ==null && cb.Checked )
{
...
}

If cb is null, then the if will fail but the second test of the if will crash becuase cb is null.

Try this:

if(cb==null)
{
    if(cb.Checked)
    {
    ...
    }
}

-Peter
Reply With Quote
  #9 (permalink)  
Old May 4th, 2005, 06:50 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Wait, sorry, that makes no sense. Why would you test for cb==null AND see if it's checked??

-Peter
Reply With Quote
  #10 (permalink)  
Old May 4th, 2005, 03:53 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

peter,this doesn't crash if cb is null because of compiler optimization,
if(cb ==null || cb.Checked ){}

_____________
Mehdi.
software student.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot implicitly convert type ... lcarpay ASP.NET 2.0 Basics 3 June 22nd, 2007 11:20 PM
cant implicitly convert type int to bool muskaanbajaj BOOK: ASP.NET Website Programming Problem-Design-Solution 3 November 19th, 2005 03:57 PM
How to Convert a int in a bool with FormatStrings ShadowMoon Classic ASP Basics 2 October 26th, 2004 05:53 AM
Can't convert type 'bool' to 'int' Gjerstad BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 9th, 2003 10:33 AM



All times are GMT -4. The time now is 06:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.