473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ASP.NET and checkbox help

Hi all,

I'm new to ASP.NET and am working through a few exercises in a book to get
up to speed. First, some background:

I'm running SQL Server 2000 and have one field as a bit data type (0=false
or 1=true). On a form I have a check box that a user can check for whatever
reason. This field saves properly to the DB.

However, my problem is in editing the field. When I click a link to update
a record, the checkbox is always unchecked. If I leave it unchecked it
updates the field to show as false. I can't seem to get it to enable based
on the data from the dataset. it looks like I've got it set to dynamic as
well (I'm using Dreamweaver to develop).

In the parameter tag I have this:

<Parameter Name="@access" Value='<%# IIf((Request.Form("EditPages") <>
Nothing), Request.Form("access"), "") %>' Type="Boolean" />

And for the actual checkbox I have:

<asp:checkbox id="EditPages" runat="server" checked='<%#
IIf((dsUpdate.FieldValue("EditPages", Container) = "1"), true, false) %>' />

Now, again - new to ASP.NET (.NET in general) and I can't follow this logic.
An someone walk me through it? Also - why are If statements IIF (with 2
I's?)

Thanks for your newbie patience! :)

Dave

Nov 19 '05 #1
5 1694
To answer the last question: IIf is not an if statement, at least not
directly; it is an if ... else.

The statement you have state:

if(Request.Form("EditPages")
'Get from the database
else
'do not

The statement looks fine, but the methodology you are using is very ASP, not
ASP.NET. The concept of determining where you are based on form tags is the
improper part. If it were coded in Page_Load, you would likely code:

If(Not Page.IsPostback) Then
'set up the page
Else
If Request.Form("EditPages") <> Nothing Then
End If
End If

As each button produces its own event, the above methodology is quite error
prone.

I assume there is an edit version of a page and a non-edit? If not, your IIf
is completely unnecessary.

What I would do is code everything in code behind rather than use the drag
and drop, declarative methodology. This will help you understand .NET better.
If, later, you wish to go back to declarative, that is your prerogative. YOu
will still understand the model better.

The basics are like so (assuming SQL Server, change class names for other
DBs):

'Get data
Dim connString as String = "{your connection string here}"
Dim sql as String = "{SQL Statement to get your data to edit}"

Dim conn As New SqlConnection(connString)
Dim cmd As New SqlCommand(sql, conn)

Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet("NameHere")

Try
conn.Open()
da.Fill(ds)
Catch Ex As Exception
'Add excption handler
Finally
If (conn.State = ConnectionState.Open) Then
conn.Close()
End If

conn.Dispose()

End Try

You can now bind from the one row returned (assume it is one row):

CheckBox1.Checked = ds.Tables("NameHere").Rows(0)("CheckboxField")

This methodology allows you to ignore the bind on a non-edit, by only adding
the binding routine on the edit button click (or hyperlink, etc.)

Hopefully this makes sense. If not, my suggestion is to move to C#. You will
be less likely to bring ASP/VB COM baggage into .NET if you switch languages.
You can always switch back to VB.NET later, after you have the paradigm shift
down.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Dave" wrote:
Hi all,

I'm new to ASP.NET and am working through a few exercises in a book to get
up to speed. First, some background:

I'm running SQL Server 2000 and have one field as a bit data type (0=false
or 1=true). On a form I have a check box that a user can check for whatever
reason. This field saves properly to the DB.

However, my problem is in editing the field. When I click a link to update
a record, the checkbox is always unchecked. If I leave it unchecked it
updates the field to show as false. I can't seem to get it to enable based
on the data from the dataset. it looks like I've got it set to dynamic as
well (I'm using Dreamweaver to develop).

In the parameter tag I have this:

<Parameter Name="@access" Value='<%# IIf((Request.Form("EditPages") <>
Nothing), Request.Form("access"), "") %>' Type="Boolean" />

And for the actual checkbox I have:

<asp:checkbox id="EditPages" runat="server" checked='<%#
IIf((dsUpdate.FieldValue("EditPages", Container) = "1"), true, false) %>' />

Now, again - new to ASP.NET (.NET in general) and I can't follow this logic.
An someone walk me through it? Also - why are If statements IIF (with 2
I's?)

Thanks for your newbie patience! :)

Dave

Nov 19 '05 #2
Hi Dave,

It is hard to see where your problem is given the amount of code you posted.
Perhaps you could show some more?

As for the second part, IIF is a handy function that returns one of two
"answers" according to the result of the analysis.

In your case, the code appears to be evaluating this expression:

(dsUpdate.FieldValue("EditPages", Container) = "1")

which (I assume) means evaluate whether the value of the field in EditPages
is "1".

If the value is "1", the boolean result is true. If not, the boolean result
is false.

At that point, IIF has something it can work with - a logical value. IIF
looks at the logical value and if it is true, it returns the value after the
comma. If the logical value is false, it returns the value after the second
comma which in this case is also false.

Here's the explanation in the docs:

http://msdn.microsoft.com/library/de...l/vafctIIF.asp

<asp:checkbox id="EditPages" runat="server" checked='<%#
IIf((dsUpdate.FieldValue("EditPages", Container) = "1"), true, false) %>' />

Ken
MVP [ASP.NET]
Toronto
"Dave" <ov******@cogeco.ca> wrote in message
news:uz**************@TK2MSFTNGP15.phx.gbl...
Hi all,

I'm new to ASP.NET and am working through a few exercises in a book to get
up to speed. First, some background:

I'm running SQL Server 2000 and have one field as a bit data type (0=false
or 1=true). On a form I have a check box that a user can check for
whatever
reason. This field saves properly to the DB.

However, my problem is in editing the field. When I click a link to
update
a record, the checkbox is always unchecked. If I leave it unchecked it
updates the field to show as false. I can't seem to get it to enable
based
on the data from the dataset. it looks like I've got it set to dynamic as
well (I'm using Dreamweaver to develop).

In the parameter tag I have this:

<Parameter Name="@access" Value='<%# IIf((Request.Form("EditPages") <>
Nothing), Request.Form("access"), "") %>' Type="Boolean" />

And for the actual checkbox I have:

<asp:checkbox id="EditPages" runat="server" checked='<%#
IIf((dsUpdate.FieldValue("EditPages", Container) = "1"), true, false) %>'
/>

Now, again - new to ASP.NET (.NET in general) and I can't follow this
logic.
An someone walk me through it? Also - why are If statements IIF (with 2
I's?)

Thanks for your newbie patience! :)

Dave


Nov 19 '05 #3
Hi Ken,

Thanks for the walk through!

OK - So the IIF, for whatever reason isn't triggering properly. even though
the value of the editpages field is 1 it doesn't check the box. Could it be
because the datatype is a BIT and it is evaluating it againts a text string?

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Dave,

It is hard to see where your problem is given the amount of code you
posted. Perhaps you could show some more?

As for the second part, IIF is a handy function that returns one of two
"answers" according to the result of the analysis.

In your case, the code appears to be evaluating this expression:

(dsUpdate.FieldValue("EditPages", Container) = "1")

which (I assume) means evaluate whether the value of the field in
EditPages is "1".

If the value is "1", the boolean result is true. If not, the boolean
result is false.

At that point, IIF has something it can work with - a logical value. IIF
looks at the logical value and if it is true, it returns the value after
the comma. If the logical value is false, it returns the value after the
second comma which in this case is also false.

Here's the explanation in the docs:

http://msdn.microsoft.com/library/de...l/vafctIIF.asp

<asp:checkbox id="EditPages" runat="server" checked='<%#
IIf((dsUpdate.FieldValue("EditPages", Container) = "1"), true, false) %>'
/>

Ken
MVP [ASP.NET]
Toronto
"Dave" <ov******@cogeco.ca> wrote in message
news:uz**************@TK2MSFTNGP15.phx.gbl...
Hi all,

I'm new to ASP.NET and am working through a few exercises in a book to
get
up to speed. First, some background:

I'm running SQL Server 2000 and have one field as a bit data type
(0=false
or 1=true). On a form I have a check box that a user can check for
whatever
reason. This field saves properly to the DB.

However, my problem is in editing the field. When I click a link to
update
a record, the checkbox is always unchecked. If I leave it unchecked it
updates the field to show as false. I can't seem to get it to enable
based
on the data from the dataset. it looks like I've got it set to dynamic
as
well (I'm using Dreamweaver to develop).

In the parameter tag I have this:

<Parameter Name="@access" Value='<%# IIf((Request.Form("EditPages") <>
Nothing), Request.Form("access"), "") %>' Type="Boolean" />

And for the actual checkbox I have:

<asp:checkbox id="EditPages" runat="server" checked='<%#
IIf((dsUpdate.FieldValue("EditPages", Container) = "1"), true, false) %>'
/>

Now, again - new to ASP.NET (.NET in general) and I can't follow this
logic.
An someone walk me through it? Also - why are If statements IIF (with 2
I's?)

Thanks for your newbie patience! :)

Dave

Nov 19 '05 #4
> Could it be because the datatype is a BIT and it is evaluating it againts
a text string?
That's my guess.
"Dave" <ov******@cogeco.ca> wrote in message
news:u2**************@TK2MSFTNGP15.phx.gbl... Hi Ken,

Thanks for the walk through!

OK - So the IIF, for whatever reason isn't triggering properly. even
though the value of the editpages field is 1 it doesn't check the box.
Could it be because the datatype is a BIT and it is evaluating it againts
a text string?


Nov 19 '05 #5
Yep - that was it.

changed it from:

IIf((dsUpdate.FieldValue("EditPages", Container) = "1"), true, false) %>'
/>

To:

IIf((dsUpdate.FieldValue("EditPages", Container) = true), true, false) %>'
/>

and worked like a charm!
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u$**************@TK2MSFTNGP15.phx.gbl...
Could it be because the datatype is a BIT and it is evaluating it againts
a text string?


That's my guess.
"Dave" <ov******@cogeco.ca> wrote in message
news:u2**************@TK2MSFTNGP15.phx.gbl...
Hi Ken,

Thanks for the walk through!

OK - So the IIF, for whatever reason isn't triggering properly. even
though the value of the editpages field is 1 it doesn't check the box.
Could it be because the datatype is a BIT and it is evaluating it againts
a text string?

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fabri | last post by:
How can I, on button click, to select ONLY the following 4 checkbox? I would like to do this without a for loop through form.lenght because this is only an example and I have to apply this script...
2
by: Thomas R | last post by:
Is is possible? In VS.NET 2003, Binding data to the repeater is easy, but when I try to add an ASP:checkbox to the .aspx page, the designer won't recognize it, hence the code view doesn't allow...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
9
by: raamay | last post by:
I have six checkboxes as shown below: <table> <tr> <td><input name="spec1" type="checkbox" value="0" tabindex="11" /><label id="label">Bridge Construction</label></td> </tr> <tr> <td><input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.