ASP CheckBox problem

Daeva

In Runtime
Messages
407
I have a solution to this problem already, but it's not pretty and i'd like to see if there is a better one. Here is the problem:

I have a database, and in that database there is a table called Servers.
This is a Microsoft SQL Server Express Database(Not enterprise level).
The database contains the following fields (this is not a complete list of all fields):
serverID int identity,
networkID int not null,
customerID int not null,
serverName varchar(25) not null,

And these are the fields in question

PDC tinyint,
BDC tinyint,
EXCH tinyint,
SQL tinyint,
WWW tinyint,
FTP tinyint,
WTS tinyint,
DHCP tinyint,
DNS tinyint,
WINS tinyint,
POP tinyint,
SMTP tinyint,
PPTP tinyint,
isBackup tinyint.

Now I have a formView control on my asp.net page, the control has a readOnly and Edit mode, no insert. Those fields are representative of boolean values, and when adding a server to the database I just use a for loop to populate the various different values:

Dim x As Integer = New Integer
Dim y As Integer = 17
Dim myVar As Integer = New Integer
For x = 0 To 13 Step 1
If CType(Me.addServerFormView.FindControl("infoCheckBoxList"), CheckBoxList).Items(x).Selected() = True Then
myVar = 1
Else
myVar = 0
End If
Me.SqlDataSource1.InsertParameters(y).DefaultValue() = myVar
y = y + 1
Next

This is where SqlDataSource1's insert parameters for the afore mentioned database fields starts at field 17 and there are 13 values.

That works fine, now the question is, when outputting these values, I have to systematically(with a for loop) check to see if the value is 0 or 1, and if it is, display the proper text corresponding to the field name. if 1 then the server has that capability and display the text, and if 0 then don't display the text but still pass the value 0 for the update from read Only mode.

Sorry, this is a lot to articulate at once, I may need to clarify some things.
Now the problem is that all of this required a lot of code, and looking through the page. For those not very familiar with vb, the FindControl() Method is similar to javascript's getElementById(), only you have to adhere to stricter XML standards as far as child vs root elements go. Then to output the values to the read only, I have invisible <asp>'s that get the value, be it 0 or 1. I then have code that says when these are done loading, get the values, and change the text in these textboxes to the field name, be it PDC(Primary Data Server), or BDC(Backup Data Server) just to name a few. That is a pretty messy way of getting things done, and it's not 100% reliable i've found out. What can I do?
 
Back
Top Bottom