loop through, get the values from them and insert them into a db. each
one should be a separate record... Can anyone please give me some kind
of example on how to do this?? I am doing this in asp.net VB.
Please let me know if you need any additional information.
ThanksIf they are plain HTML radio buttons, you can't loop through them in
server-side code. It must be done from client-side code.
"Brian" <bciarcia@.pepehazard.com> wrote in message
news:1109213918.751967.126580@.f14g2000cwb.googlegr oups.com...
>I have a list of plain HTML radio buttons that I want to be able to
> loop through, get the values from them and insert them into a db. each
> one should be a separate record... Can anyone please give me some kind
> of example on how to do this?? I am doing this in asp.net VB.
> Please let me know if you need any additional information.
> Thanks
Can you elaborate on looping through radio buttons?
If the radio buttons are defined by you, why do you need to loop
through them after submission? And you can select only one item in a
radiobutton-group.
Can you give an example of what you are trying to achieve? That may
help in analysing the problem better.
--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
----------
to get most of the help in this group, you better post a try of ur code.
asking plain questions like this usually is missleading or says that you
haven't tried anything in the first place.
why don't u try to do it in ur own code and post ur code so u can have
better guidance. i hope u find the answer as soon as possible ;)
"Brian" <bciarcia@.pepehazard.com> wrote in message
news:1109213918.751967.126580@.f14g2000cwb.googlegr oups.com...
>I have a list of plain HTML radio buttons that I want to be able to
> loop through, get the values from them and insert them into a db. each
> one should be a separate record... Can anyone please give me some kind
> of example on how to do this?? I am doing this in asp.net VB.
> Please let me know if you need any additional information.
> Thanks
Thanks for the replies... Ok.. I have 8 groups of questions. I'll post
a sample of one group below. Depending on who logs in, will depend on
how many groups of questions they will get. Once they check either the
yes or no radio button for each question, the will submit the form. I
will need to know how many questions there are, then loop through those
questions and input them into the db. for example( if two of the
questions were "the sky is blue" and "the ocean is green".. One record
will be created for the first question, and another record will be
created for the second question). I also need to know if any answers
were answered yes, but that is a separate issue. Right now, I just need
to know how to do this part... Here is a sample of the questions. These
are being stored in a questions table in the db.
---------------
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<th noWrap>
<div align="center"><span class="style3">Coronary Artery Disease
</span></div></th>
<th><span class="style3">YES</span></th>
<th><span class="style3">NO</span></th></tr>
<tr>
<td noWrap width="69%"><span class="style3">Have you ever received a
diagnosis of heart disease or coronary artery disease?</span></td>
<td width="6%">
<div align="center">
<input type="radio" value="yes" name="CAD_1" /> </div></td>
<td width="6%">
<div align="center">
<input type="radio" value="no" name="CAD_1" /> </div></td></tr>
<tr>
<td class="style3" noWrap>Have you ever had a heart attack?</td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_2" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_2" /> </div></td></tr>
<tr>
<td class="style3" noWrap>Have you ever been treated for a blocked atery
anywhere in your body? </td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_3" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_3" /> </div></td></tr>
<tr>
<td class="style3" noWrap><span class="style4">Have you ever been
treated for chest pain caused by blockage of arteries in your heart?
</span></td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_4" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_4" /> </div></td></tr>
<tr>
<td class="style3" noWrap><span class="style4">Have you ever had an
abnormal exercise tolerance test (ETT, stress test) </span></td>
<td>
<div align="center">
<input type="radio" value="yes" name="CAD_5" /> </div></td>
<td>
<div align="center">
<input type="radio" value="no" name="CAD_5" />
</div></td></tr></tbody></table
---------------
I am just querying the db and grabbing the appropriate groups.. The
names of the radios are important too, per the customers request.
Another group would be CHF_1,CHF_2, etc.. If anyone knows a better way
of doing this, I'll be glad to hear it... Let me know if you need
anymore detail..
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
If there are only 8 questions (and each radio button in a group are all
named the same name), you don't need to loop at all. Just check all 8
groups to see if a group has a value. If a group has a value, then that
question was responded to.
Or, since they are submitting the data to the server, you could just check
the Request object in the same way to see what data was submitted.
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:e%23hIL2lGFHA.1096@.tk2msftngp13.phx.gbl...
> Thanks for the replies... Ok.. I have 8 groups of questions. I'll post
> a sample of one group below. Depending on who logs in, will depend on
> how many groups of questions they will get. Once they check either the
> yes or no radio button for each question, the will submit the form. I
> will need to know how many questions there are, then loop through those
> questions and input them into the db. for example( if two of the
> questions were "the sky is blue" and "the ocean is green".. One record
> will be created for the first question, and another record will be
> created for the second question). I also need to know if any answers
> were answered yes, but that is a separate issue. Right now, I just need
> to know how to do this part... Here is a sample of the questions. These
> are being stored in a questions table in the db.
> ---------------
> <table cellspacing="0" cellpadding="0" width="100%" border="0">
> <tbody>
> <tr>
> <th noWrap>
> <div align="center"><span class="style3">Coronary Artery Disease
> </span></div></th>
> <th><span class="style3">YES</span></th>
> <th><span class="style3">NO</span></th></tr>
> <tr>
> <td noWrap width="69%"><span class="style3">Have you ever received a
> diagnosis of heart disease or coronary artery disease?</span></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="yes" name="CAD_1" /> </div></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="no" name="CAD_1" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever had a heart attack?</td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_2" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_2" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever been treated for a blocked atery
> anywhere in your body? </td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_3" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_3" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever been
> treated for chest pain caused by blockage of arteries in your heart?
> </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_4" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_4" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever had an
> abnormal exercise tolerance test (ETT, stress test) </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_5" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_5" />
> </div></td></tr></tbody></table>
> ---------------
> I am just querying the db and grabbing the appropriate groups.. The
> names of the radios are important too, per the customers request.
> Another group would be CHF_1,CHF_2, etc.. If anyone knows a better way
> of doing this, I'll be glad to hear it... Let me know if you need
> anymore detail..
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Actually, it is 8 groups of questions and the names are different..
(ie.. group one.. the names are CAD_1,CAD_2,CAD_3 group two.. the names
are CHF_1,CHF_2,CHF_3,CHF_4. etc..) Each group has a different number
of questions. Each question has to have an answer, either yes or no..
Since this is an asp.net page, I have no clue How to get the answers
into the database. CAD_1 has to have its own record, CAD_2 has to have
its own record, etc, etc.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
try to put the group of radio buttons in a web control PlaceHolder, make
those radio buttons Web controls instead of HTML in that PlaceHolder.
then you can use :
foreach( Control c in placeHolder.Controls )
{
//cast the control to web radio button and do what ever u like with it
}
i hope this helps
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:e%23hIL2lGFHA.1096@.tk2msftngp13.phx.gbl...
> Thanks for the replies... Ok.. I have 8 groups of questions. I'll post
> a sample of one group below. Depending on who logs in, will depend on
> how many groups of questions they will get. Once they check either the
> yes or no radio button for each question, the will submit the form. I
> will need to know how many questions there are, then loop through those
> questions and input them into the db. for example( if two of the
> questions were "the sky is blue" and "the ocean is green".. One record
> will be created for the first question, and another record will be
> created for the second question). I also need to know if any answers
> were answered yes, but that is a separate issue. Right now, I just need
> to know how to do this part... Here is a sample of the questions. These
> are being stored in a questions table in the db.
> ---------------
> <table cellspacing="0" cellpadding="0" width="100%" border="0">
> <tbody>
> <tr>
> <th noWrap>
> <div align="center"><span class="style3">Coronary Artery Disease
> </span></div></th>
> <th><span class="style3">YES</span></th>
> <th><span class="style3">NO</span></th></tr>
> <tr>
> <td noWrap width="69%"><span class="style3">Have you ever received a
> diagnosis of heart disease or coronary artery disease?</span></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="yes" name="CAD_1" /> </div></td>
> <td width="6%">
> <div align="center">
> <input type="radio" value="no" name="CAD_1" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever had a heart attack?</td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_2" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_2" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap>Have you ever been treated for a blocked atery
> anywhere in your body? </td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_3" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_3" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever been
> treated for chest pain caused by blockage of arteries in your heart?
> </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_4" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_4" /> </div></td></tr>
> <tr>
> <td class="style3" noWrap><span class="style4">Have you ever had an
> abnormal exercise tolerance test (ETT, stress test) </span></td>
> <td>
> <div align="center">
> <input type="radio" value="yes" name="CAD_5" /> </div></td>
> <td>
> <div align="center">
> <input type="radio" value="no" name="CAD_5" />
> </div></td></tr></tbody></table>
> ---------------
> I am just querying the db and grabbing the appropriate groups.. The
> names of the radios are important too, per the customers request.
> Another group would be CHF_1,CHF_2, etc.. If anyone knows a better way
> of doing this, I'll be glad to hear it... Let me know if you need
> anymore detail..
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Im sorry.. I'm really ignorant when it comes to this... How do I put it
in a placeholder? can I still store the groups in the database?? I
feel like such an idiot now..
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
you are not idiot at all, all what you need is more reading. go to the msdn
and read more about the place holder :)
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:egVPsonGFHA.3876@.TK2MSFTNGP14.phx.gbl...
> Im sorry.. I'm really ignorant when it comes to this... How do I put it
> in a placeholder? can I still store the groups in the database?? I
> feel like such an idiot now..
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Brian,
If you use standard HTML radio buttons (<INPUT TYPE="radio">), then you
should name all the radio buttons for a given question the same name. That
way each question will have exactly ONE radio button that holds the answer
to the question. With standard HTML radio buttons, this is also what gives
them their mutual exclusivity.
As I said earlier, since the answers to all the questions that were asked
are going to be sent to the server via a submit, you can just query the
Request object to see what data it contains. By doing this, you will know
which questions were asked since only those answers would have been sent to
the server.
[VB.NET]
Dim answer as String
For Each Answer In Request.Form
'references to answer return the name of the item
'references to Request.Form(answer) refer to the value of the item
Next
-Scott
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:OkmAyXnGFHA.2420@.TK2MSFTNGP14.phx.gbl...
> Actually, it is 8 groups of questions and the names are different..
> (ie.. group one.. the names are CAD_1,CAD_2,CAD_3 group two.. the names
> are CHF_1,CHF_2,CHF_3,CHF_4. etc..) Each group has a different number
> of questions. Each question has to have an answer, either yes or no..
> Since this is an asp.net page, I have no clue How to get the answers
> into the database. CAD_1 has to have its own record, CAD_2 has to have
> its own record, etc, etc.
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Scott,
Thanks... I swear I tried something like that before, but it didn't
work.. I just tried it using your code and it works great.. So now I am
looping through the questions when I submit to another page. Can I put
that code in the codebehind on this page, or does this form have to be
submitted to another page? If so, can I add this code to the codebehind
on the submission page?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
In ASP.NET server-forms submit to the same page. You can add this code to
whatever code-behind you submit to.
You may want to use the Web Forms Panel control to hold the 8 groups of
questions (you'll need 8 panel controls). Then it is simply a matter of
setting the visible property of the correct panel to true and all others to
false. This way you can do all your work in one .aspx page with just one
code-behind.
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:egrJPKoGFHA.3628@.TK2MSFTNGP15.phx.gbl...
> Scott,
> Thanks... I swear I tried something like that before, but it didn't
> work.. I just tried it using your code and it works great.. So now I am
> looping through the questions when I submit to another page. Can I put
> that code in the codebehind on this page, or does this form have to be
> submitted to another page? If so, can I add this code to the codebehind
> on the submission page?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Ok.. I'll look into the web form panel... do you know where I can find
any reading on that??
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ok.. I'll look into the web form panel... do you know where I can find
any reading on that??
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
If I use the panels, do I then have to change the radio buttons to
asp:radiobuttons or can I keep them as regular buttons?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
You can use any controls on a panel that you like.
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:ecIFBepGFHA.2356@.TK2MSFTNGP12.phx.gbl...
> If I use the panels, do I then have to change the radio buttons to
> asp:radiobuttons or can I keep them as regular buttons?
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
ok.. i know you probably think I am a pain in the _ss right now, but to
control the visibility of those panels, would I do something like this?
I set the Panel ID's to be CAD, HB, CHF, DBTS. The customer I am
pulling up only should see CAD and HB.
foreach( Control c in Panel.Controls )
If (objBarDataReader("ProgramID") = Panel(c) then
Panel(c).visibility = "true"
end if
next
Is that Close???
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I got it.. I did this;
Dim ctl as Control
For Each ctl In Page.Controls
If TypeOf (ctl) Is System.Web.UI.WebControls.Panel Then
If ctl.ID = objBarDataReader("ProgramID") Then
ctl.visible = True
End If
End If
Next
----------------
That worked.. Ok.. so now when I hit submit, I just create an onclick
event and put that code that you gave me earlier in there, correct?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I just added this code to my codebehind and now my questions wont
display.. Am I doing something wrong??
I created an asp:button called LoginButton and created a label called
errormessage.
I am just trying to display the results so I can see what is happening.
----------------
Private Sub LoginButton_Click(ByVal sender as System.Object, ByVal e as
System.EventArgs) Handles LoginButton.Click
Dim answer as String
Dim AnsStr
For Each Answer In Request.Form
'references to answer return the name of the item
AnsStr = AnsStr & "the answer to question " & answer & " is " &
Request.Form(answer) & "<br>"
Next
errormessage.Text = AnsStr
end sub
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ok.. It seems that when I added the button control and the label
control, the code that I used to enable the view state of the panels
stopped working.. As soon as I take them away, it works... Why is that
happening?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I'm not sure I'm following what is happening at this point, but you want to
make sure that the first panel has its visibility set to True right from the
start so that the user will get the first set of questions right away.
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:eVSgierGFHA.3072@.tk2msftngp13.phx.gbl...
> Ok.. It seems that when I added the button control and the label
> control, the code that I used to enable the view state of the panels
> stopped working.. As soon as I take them away, it works... Why is that
> happening?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
I created my panels and set them to be hidden by default. When the page
loads, it checks to see what panels they should see and makes them
visible. Everything worked great with the code you gave me.. I then
changed the regular submit button to an asp:button and added an
asp:label. As soon as I added that, the code that makes the panels
visible, stopped working.. If I change the asp:button back and get rid
of the lable... it works fine..
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
URGHHH... I give up... Now I can't even get it to work no matter what I
try.. Here is my codebehind.. Please tell me what is wrong...
------------------
Public Class Questions2 : Inherits Page
Protected WithEvents CAD As System.Web.UI.WebControls.panel
Protected WithEvents CHF As System.Web.UI.WebControls.panel
Protected WithEvents HB As System.Web.UI.WebControls.panel
Protected WithEvents DBTS As System.Web.UI.WebControls.panel
Public Sub Page_Load(Source As Object, E As System.EventArgs)
if NOT Page.IsPostback Then
GetQuestions()
end if
End Sub
'///////////////////////////////////////////////////////////////////////
///////////
'////////////////////////////// QUESTIONNAIRE QUERY
//////////////////////////////
'///////////////////////////////////////////////////////////////////////
//////////
public Sub GetQuestions()
Dim strbarConn as string =
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_ST
RING_cardmemberoledb")
Dim strbarSQL as String = "SELECT ProgramID, QuestionHTML from
SponsorQuestions where SponsorID = '" & session("SponsorCode") & "'
order by QuestionCode"
Dim objBarConnection as New OledbConnection(strbarConn)
Dim objBarCommand as New OledbCommand(strBarSQL, objBarConnection)
Dim objBarDataReader as OledbDatareader
objBarConnection.open()
objBarDataReader = objBarCommand.ExecuteReader()
Do While objBarDataReader.Read()=True
' response.write(strbarSQL)
Dim ctl as Control
For Each ctl In Page.Controls
Response.write(ctl)
If TypeOf (ctl) Is System.Web.UI.WebControls.Panel Then
If ctl.ID = objBarDataReader("ProgramID") Then
ctl.visible = True
End If
End If
Next
Loop
objBarDataReader.Close()
objBarConnection.Close()
End Sub
End Class
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Well, I see that in your Page_Load event you aren't doing anything when it
IS a postback. So it would seem that on the first page call you'd get the
page and after that, you'd get absolutely nothing. Make sure to either turn
off the ViewState (EnableViewState property) for each panel so that they
always start out being invisible or add code to your IsPostBack that shuts
off the last panel.
I think it should be (I've also cleaned up your code a bit):
-----------------------
Imports System.Configuration
Imports System.Data.OleDB
Public Class Questions2
Protected WithEvents CAD As System.Web.UI.WebControls.panel
Protected WithEvents CHF As System.Web.UI.WebControls.panel
Protected WithEvents HB As System.Web.UI.WebControls.panel
Protected WithEvents DBTS As System.Web.UI.WebControls.panel
-----------------------
Public Sub Page_Load(Source As Object, E As System.EventArgs)
If Not IsPostBack Then
'Page is loading for first time
'Show whatever the user is supposed to see on the first page load
Else
'Page is loading in response to the form being submitted
'Figure out which questions to show them next
GetQuestions()
End If
End Sub
-----------------------
Public Sub GetQuestions()
Dim strbarConn as string = _
ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_cardmemberoledb")
Dim strbarSQL as String = "SELECT ProgramID, QuestionHTML " & _
"FROM SponsorQuestions WHERE
SponsorID = '" & _
Session("SponsorCode") & "'
ORDER BY QuestionCode"
Dim objBarConnection as New OledbConnection(strbarConn)
Dim objBarCommand as New OledbCommand(strBarSQL, objBarConnection)
Try
objBarConnection.open()
Dim objBarDataReader as OledbDatareader =
objBarCommand.ExecuteReader()
Do While objBarDataReader.Read
' response.write(strbarSQL)
Dim ctl as Control
For Each ctl In Controls
Response.Write(ctl)
If TypeOf (ctl) Is Panel Then
If ctl.ID = objBarDataReader("ProgramID") Then
ctl.visible = True
End If
End If
Next
Loop
Catch ex As OleDBException
'Handle exceptions here
Finally
objBarDataReader.Close()
objBarConnection.Close
End Try
End Sub
-----------------------
End Class
-----------------------
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:OXOkecuGFHA.2740@.TK2MSFTNGP12.phx.gbl...
> URGHHH... I give up... Now I can't even get it to work no matter what I
> try.. Here is my codebehind.. Please tell me what is wrong...
> ------------------
>
> Public Class Questions2 : Inherits Page
>
> Protected WithEvents CAD As System.Web.UI.WebControls.panel
> Protected WithEvents CHF As System.Web.UI.WebControls.panel
> Protected WithEvents HB As System.Web.UI.WebControls.panel
> Protected WithEvents DBTS As System.Web.UI.WebControls.panel
>
>
> Public Sub Page_Load(Source As Object, E As System.EventArgs)
> if NOT Page.IsPostback Then
> GetQuestions()
> end if
>
>
> End Sub
>
>
> '///////////////////////////////////////////////////////////////////////
> ///////////
> '////////////////////////////// QUESTIONNAIRE QUERY
> //////////////////////////////
> '///////////////////////////////////////////////////////////////////////
> //////////
> public Sub GetQuestions()
>
> Dim strbarConn as string =
> System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_ST
> RING_cardmemberoledb")
> Dim strbarSQL as String = "SELECT ProgramID, QuestionHTML from
> SponsorQuestions where SponsorID = '" & session("SponsorCode") & "'
> order by QuestionCode"
> Dim objBarConnection as New OledbConnection(strbarConn)
> Dim objBarCommand as New OledbCommand(strBarSQL, objBarConnection)
> Dim objBarDataReader as OledbDatareader
> objBarConnection.open()
> objBarDataReader = objBarCommand.ExecuteReader()
> Do While objBarDataReader.Read()=True
> ' response.write(strbarSQL)
>
> Dim ctl as Control
> For Each ctl In Page.Controls
> Response.write(ctl)
> If TypeOf (ctl) Is System.Web.UI.WebControls.Panel Then
> If ctl.ID = objBarDataReader("ProgramID") Then
> ctl.visible = True
> End If
> End If
> Next
> Loop
> objBarDataReader.Close()
> objBarConnection.Close()
> End Sub
>
> End Class
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Now I get this error...
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
Line 399: Finally
Line 400: objBarDataReader.Close()<---
Line 401: objBarConnection.Close
Line 402: End Try
Line 400 is the problem...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nevermind.. Dumb error on my part... However, It still doesn't seem to
be seeing the panels as controls Here is the code.. I put some
response.writes in their to confirm the query is running right and to
see what ctls are being seen..
------------------
Dim ctl as Control
For Each ctl In Controls
Response.Write("the control is " )
response.write(ctl)
response.write(" <BR> TheID is " & objBarDataReader("ProgramID") &
"<BR> the sessionID is " & session("SponsorCode"))
If TypeOf (ctl) Is Panel Then
If ctl.ID = objBarDataReader("ProgramID") Then
ctl.visible = True
else
ctl.visible = false
End If
End If
Next
----------------
Here is the result of the response.writes..
---------------
the control is ASP.header_ascx
TheID is CAD
the sessionID is PB
the control is System.Web.UI.HtmlControls.HtmlForm
TheID is CAD
the sessionID is PB
the control is ASP.header_ascx
TheID is CHF
the sessionID is PB
the control is System.Web.UI.HtmlControls.HtmlForm
TheID is CHF
the sessionID is PB
the control is ASP.header_ascx
TheID is DBTS
the sessionID is PB
the control is System.Web.UI.HtmlControls.HtmlForm
TheID is DBTS
the sessionID is PB
------------------
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
The reason why its not working is that the controls (panels) aren't being
added to the form's conrols collection as Panel controls, they are being
added as HTMLLiteral controls, so the loop is never finding them.
You need to add the panel controls to the form's controls collection maually
so they will be treated as Panel controls when you loop through the controls
collection.
I have changed the code a little and it works for me (this assumes there are
3 panels called Panel1, Panel2 and Panel3).
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Controls.Add(Panel1)
Me.Controls.Add(Panel2)
Me.Controls.Add(Panel3)
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim pnl As Object
For Each pnl In Controls
If pnl.GetType Is GetType(System.Web.UI.WebControls.Panel) Then
Label1.Text += "<BR>" & CType(pnl,
System.Web.UI.WebControls.Panel).ID
End If
Next
End Sub
-Scott
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:umNPj8zGFHA.3648@.TK2MSFTNGP09.phx.gbl...
> Nevermind.. Dumb error on my part... However, It still doesn't seem to
> be seeing the panels as controls Here is the code.. I put some
> response.writes in their to confirm the query is running right and to
> see what ctls are being seen..
> ------------------
> Dim ctl as Control
> For Each ctl In Controls
> Response.Write("the control is " )
> response.write(ctl)
> response.write(" <BR> TheID is " & objBarDataReader("ProgramID") &
> "<BR> the sessionID is " & session("SponsorCode"))
> If TypeOf (ctl) Is Panel Then
> If ctl.ID = objBarDataReader("ProgramID") Then
> ctl.visible = True
> else
> ctl.visible = false
> End If
> End If
> Next
> ----------------
> Here is the result of the response.writes..
> ---------------
> the control is ASP.header_ascx
> TheID is CAD
> the sessionID is PB
> the control is System.Web.UI.HtmlControls.HtmlForm
> TheID is CAD
> the sessionID is PB
> the control is ASP.header_ascx
> TheID is CHF
> the sessionID is PB
> the control is System.Web.UI.HtmlControls.HtmlForm
> TheID is CHF
> the sessionID is PB
> the control is ASP.header_ascx
> TheID is DBTS
> the sessionID is PB
> the control is System.Web.UI.HtmlControls.HtmlForm
> TheID is DBTS
> the sessionID is PB
> ------------------
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Sorry man.. Its still not working.. I dont understand... I created the
label named label1 and its not even seeing that to populate the label
with the information.. the only thing it sees is the form itself and the
header that i have..
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
The code I gave you works for me. You must not be following it or you must
have additional code in there that is interfering. Try this:
1. Make a new Web Form in your project.
2. Set it as the Start Page for the project.
3. Add 3 panel controls on the page (don't change their ID's, leave them as
Panel1...Panel3)
4. Add 1 label on the page (don't change it's ID), but clear out its text
property
5. Add this into the Web Form Designer Generated Code Sub Initialize:
Me.Controls.Add(Panel1)
Me.Controls.Add(Panel2)
Me.Controls.Add(Panel3)
6. Make this your Page_Load event:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim pnl As Object
For Each pnl In Controls
If pnl.GetType Is GetType(System.Web.UI.WebControls.Panel) Then
Label1.Text += "<BR>" & CType(pnl,
System.Web.UI.WebControls.Panel).ID
End If
Next
End Sub
7. Run the project.
8. After you get this working, you can begin to tailor it to your specific
needs.
If you take just the code I gave you in the last post
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:eD2CVQ1GFHA.3624@.tk2msftngp13.phx.gbl...
> Sorry man.. Its still not working.. I dont understand... I created the
> label named label1 and its not even seeing that to populate the label
> with the information.. the only thing it sees is the form itself and the
> header that i have..
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
I'm doing this in Dreamweaver, but I will try and create a new page,
using this code.. I didn't change the code you gave me.. I did take that
label and move it outside the form and then it magically showed up. It
has to be something with the form.. I just dont know what it is...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ah, well, more information is coming out!
How can you be doing this in DreamWeaver? You can't and you shouldn't. You
need to be using VS.NET.
DreamWeaver is the source of the "now you see it, now you don't" problems
that you are having.
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:uuNV5j1GFHA.3912@.TK2MSFTNGP10.phx.gbl...
> I'm doing this in Dreamweaver, but I will try and create a new page,
> using this code.. I didn't change the code you gave me.. I did take that
> label and move it outside the form and then it magically showed up. It
> has to be something with the form.. I just dont know what it is...
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
I know that the latest version of DreamWeaver says it supports ASP.NET, but
take it from me, stay as far away from DreamWeaver for .NET development as
you can.
Why not use the free WebMatrix ASP.NET development tool (http://asp.net) if
you don't have VS.NET. And, if you DO have VS.NET, that is most definitely
where you should be working.
"Brian Ciarcia" <bciarcia@.pepehazard.com> wrote in message
news:u2Lcwe2GFHA.3484@.TK2MSFTNGP12.phx.gbl...
> Because I dont know how to do it in VS.NET
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Because I dont know how to do it in VS.NET
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
0 comments:
Post a Comment