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