Showing posts with label displays. Show all posts
Showing posts with label displays. Show all posts

Sunday, February 19, 2012

<SelectParameters> & checked items from CheckBoxList

Column1 in table 1 has a range from 1 to 5 (int)

A CheckboxList displays these 5 items. When checked (for example 1 and 4) I want a gridview with sqldatasource=sqlProducts to display the records where column1 values 1 or 4.

When I use the code below I only get the records where column1 values 1...

<asp:SQLDataSource id="sqlProducts" Runat="Server" SelectCommand="Select * From Table1 where Column1 IN (@.CBLchecked_items)" ConnectionString="<%$ ConnectionStrings:pubs %>">
<SelectParameters>
<asp:ControlParameter Name="CBLchecked_items" ControlID="CBL" propertyname="SelectedValue" type="String" />
</SelectParameters>
</asp:SQLDataSource>

Hi~

SelectedValue returns the first selected value .

You can iterate to get all selected values:

For i = 0To Check1.Items.Count - 1If Check1.Items(i).SelectedThen' List the selected items s = s & Check1.Items(i).Text s = s &","End If Next
Hope it helps.|||

I got the problem to get the checked item in CheckBoxList here is the code :

foreach (ListItem itemin cblRoles.Items){if (item.Selected)// here the item.Selected always = false {// do something } }
 

Saturday, February 11, 2012

#Error using IIF and divide by zero

I am getting an error in a calculated field that could potentially divide by zero, even though I'm using an IIF. The column displays in the report as "#Error". My expression looks like this:

= IIF(Fields!Qty.Value = 0, "None", Fields!Hours.Value / Fields!Qty.Value)

I have successfully used this approach with INT fields, but this time the Hours field is a NUMERIC(9,2). My workaround is to do this:

IIF(Fields!Qty.Value = 0, "None", IIF(Fields!Qty.Value = 0, 42, Fields!Hours.Value) / Fields!Qty.Value)

I guess the 42 is cast to an INT inside the second IIF and the calculation works.

What's strange is that the division would even be carried out in the event of Qty = 0 from the first IIF, because the expression should just evaluate to "None" and that would be that.

Has anybody run into this problem? Is my workaround the recommended approach?

-Larry

Lawrence

Try

IIf(Fields!Income2.Value = 0, nothing,Fields!Income.Value/Fields!Income2.Value)

This works for me when my value is zero

Ham

|||

Hi Larry,

I recommend to add a custom code function for the division (in Report -> Report Properties -> Code):

Public Function Divide(ByVal first As Double, ByVal second As Double) As Double
If second = 0 Then
Return 0
Else
Return first / second
End If
End Function

Then, modify the expression accordingly:

= IIF(Fields!Qty.Value = 0, "None", Code.Divide(Fields!Hours.Value, Fields!Qty.Value))

-- Robert

|||

Thanks Robert, that's a good (dare I say) workaround. I'm still curious why the IIF errors out with the double division but works with integer division.

Also, the Edit Expression dialog has the "Divide" text underlined in red, but my project builds successfully and runs ok too. Any idea why it might think it's invalid?

-Larry

|||

Hi Ham,

Looks like I would still have to do two nested IIF statements -- one for my "None" message, and the other to return Nothing. I'm trying to avoid that. But the Code.Divide approach is working, so I'm on my way.

Thanks.

-Larry

#Error in total fields

I am getting a #error in my subtotal and total fields,
I have data in a field (on a table) as follows which displays 0.00 if there is a zero in the divide by field, otherwise it performs the divide and gives me a percentage difference from the two fields.
This works fine

=iif(Fields!REPCYINC.Value=0,0,(Fields!REPCYINC.Value) / iif(Fields!REPCYPROD.Value=0,1,Fields!REPCYPROD.Value)) * 100

Yet when i try to get this in a total field by doing an AVG it fails, and gives #error, please help, no matter how many iifs a wrap aroun dit it doesnt help.

This is the statement that #error's

=round(avg(iif(Fields!REPCYINC.Value=0,0,(Fields!REPCYINC.Value) / iif(Fields!REPCYPROD.Value=0,1,Fields!REPCYPROD.Value)) * 100) ,2)

Brian Weckler's blog has a posting related to this.

http://blogs.msdn.com/bwelcker/archive/2006/09/26/End-of-Amnesia-_2800_Avoiding-Divide-By-Zero-Errors_2900_.aspx

cheers,

Andrew

|||

Andy,

I had a similar issue recently when I used this statement:

Format(Sum(IIf(Fields!Product.Value="HEALTH",Fields!ID.Value,0)),"C")

Report Service kept giving me the #error, I located the detail error message and then I change my statement to this

Format(Sum(IIf(Fields!Product.Value="HEALTH",Fields!ID.Value,nothing)),"C") and everything worked okay. I remember the error message about mixing different types or something.

I hope this works for you.

Ham

|||

Unfortunately this post just explains what i have already posted, the issue is not the divide by zero, I have iif's to work around that and my inline divide give 0 result not #error,

I experience the #error in the group totals when i sum (As described in my original post)

If the main iif works and gives 0 then why not the sum?

These things should be straightforward!!

|||

That doesnt help, the inline iif *, 0, 0 works fine, I did try changing it to nothing although i still get the same issue, the group totals when i do a sum doesnt work, it #error's!!!

|||

sorted, regardless of how many iif's you throw around the numbers within the SSRS you MUST format the field as number otherwise #error occurs, seems like Microsft still have some work to do here.....

At LEAST make some kind of error handling reporting so we know where the error is coming from, it could be anything....

#Error displays

All,
I am getting an #Error message displaying in certain cells of a Matrix --
what causes this'
Thanks,
JimThe issue was that my MDX query was returning a string, once I wrapped the
expression in a cdbl() -- all worked,
"Jim_OLAP" wrote:
> All,
> I am getting an #Error message displaying in certain cells of a Matrix --
> what causes this'
> Thanks,
> Jim
>