 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 4th, 2005, 02:34 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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);
}
|
|

May 4th, 2005, 04:32 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You are assigning cb="" and checking.That is the problem.Check with == operator instead of =
|
|

May 4th, 2005, 05:13 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks...
but i need to know about the first problem also....ie for loop one...
Regards,
muskaan
|
|

May 4th, 2005, 05:23 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi u didnt mention the condition for it
for(i=0;i > dgemp.Items.Count-1;i++)
|
|

May 4th, 2005, 05:40 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

May 4th, 2005, 05:47 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
cb is an object..Check for null and cb.Checked
|
|

May 4th, 2005, 06:18 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

May 4th, 2005, 06:48 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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
|
|

May 4th, 2005, 06:50 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Wait, sorry, that makes no sense. Why would you test for cb==null AND see if it's checked??
- Peter
|
|

May 4th, 2005, 03:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
peter,this doesn't crash if cb is null because of compiler optimization,
if(cb ==null || cb.Checked ){}
_____________
Mehdi.
software student.
|
|
 |