|
 |
aspx_beginners thread: determine if dr is empty
Message #1 by "John Tyson" <jtyson@t...> on Mon, 9 Dec 2002 13:25:51 -0800
|
|
I have a page with two dropdown lists, one being dependent upon the
selection in the other. I am not having a problem with populating them
at page load, but when a change is made after page load. My two
dropdown lists are hardware category and hardware sub category. When
the category is changed, I pull a stored procedure that populates the
second dropdown list with appropriate selections. Some categories do
not have sub categories.
What I am trying to do is print "N/A" as the selected item in the
dropdownlist when no items are returned, or "Not selected" as the
selected field when there are items.
If Not (dr.Read()) Then
ddlTypeSub.Items.Insert(0, "N/A")
ddlTypeSub.SelectedIndex =3D 0
ddlTypeSub.SelectedItem.Value =3D 0
ddlTypeSub.SelectedItem.Text =3D "N/A"
dr.Close()
Else
ddlTypeSub.Items.Insert(0, "not selected")
ddlTypeSub.SelectedIndex =3D 0
ddlTypeSub.SelectedItem.Value =3D 0
ddlTypeSub.SelectedItem.Text =3D "not selected"
dr.Close()
End If
However, the sub category box returns the selected item "N/A" regardless
of whether there are sub category items returned for the category
selected. I tried placing "If Not page.IsPostBack" around the page load
calls that populate these dropdown lists, but that didn't make a
difference. It's probably a dumb error somewhere - can anyone offer any
advice to lessen my mental anguish?
Thanks,
John
Message #2 by Greg Griffiths <greg2@s...> on Mon, 09 Dec 2002 22:30:57 +0000
|
|
try :
if (dr.EOF) then
' no results
else
' iterate through results
end if
At 13:25 09/12/02 -0800, you wrote:
>I have a page with two dropdown lists, one being dependent upon the
>selection in the other. I am not having a problem with populating them
>at page load, but when a change is made after page load. My two
>dropdown lists are hardware category and hardware sub category. When
>the category is changed, I pull a stored procedure that populates the
>second dropdown list with appropriate selections. Some categories do
>not have sub categories.
>
>What I am trying to do is print "N/A" as the selected item in the
>dropdownlist when no items are returned, or "Not selected" as the
>selected field when there are items.
>
>If Not (dr.Read()) Then
> ddlTypeSub.Items.Insert(0, "N/A")
> ddlTypeSub.SelectedIndex = 0
> ddlTypeSub.SelectedItem.Value = 0
> ddlTypeSub.SelectedItem.Text = "N/A"
> dr.Close()
>Else
> ddlTypeSub.Items.Insert(0, "not selected")
> ddlTypeSub.SelectedIndex = 0
> ddlTypeSub.SelectedItem.Value = 0
> ddlTypeSub.SelectedItem.Text = "not selected"
> dr.Close()
>End If
>
>However, the sub category box returns the selected item "N/A" regardless
>of whether there are sub category items returned for the category
>selected. I tried placing "If Not page.IsPostBack" around the page load
>calls that populate these dropdown lists, but that didn't make a
>difference. It's probably a dumb error somewhere - can anyone offer any
>advice to lessen my mental anguish?
>
>Thanks,
>
>John
>
Message #3 by "John Tyson" <jtyson@t...> on Mon, 9 Dec 2002 14:46:14 -0800
|
|
EOF is not a member of System.Data.SqlClient.SqlDataReader.
I have also tried If Not dr Is Nothing with no luck...
-----Original Message-----
From: Greg Griffiths [mailto:greg2@s...]
Sent: Monday, December 09, 2002 2:31 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: determine if dr is empty
try :
if (dr.EOF) then
' no results
else
' iterate through results
end if
At 13:25 09/12/02 -0800, you wrote:
>I have a page with two dropdown lists, one being dependent upon the
>selection in the other. I am not having a problem with populating them
>at page load, but when a change is made after page load. My two
>dropdown lists are hardware category and hardware sub category. When
>the category is changed, I pull a stored procedure that populates the
>second dropdown list with appropriate selections. Some categories do
>not have sub categories.
>
>What I am trying to do is print "N/A" as the selected item in the
>dropdownlist when no items are returned, or "Not selected" as the
>selected field when there are items.
>
>If Not (dr.Read()) Then
> ddlTypeSub.Items.Insert(0, "N/A")
> ddlTypeSub.SelectedIndex =3D 0
> ddlTypeSub.SelectedItem.Value =3D 0
> ddlTypeSub.SelectedItem.Text =3D "N/A"
> dr.Close()
>Else
> ddlTypeSub.Items.Insert(0, "not selected")
> ddlTypeSub.SelectedIndex =3D 0
> ddlTypeSub.SelectedItem.Value =3D 0
> ddlTypeSub.SelectedItem.Text =3D "not selected"
> dr.Close()
>End If
>
>However, the sub category box returns the selected item "N/A"
regardless
>of whether there are sub category items returned for the category
>selected. I tried placing "If Not page.IsPostBack" around the page
load
>calls that populate these dropdown lists, but that didn't make a
>difference. It's probably a dumb error somewhere - can anyone offer
any
>advice to lessen my mental anguish?
>
>Thanks,
>
>John
>
Message #4 by "Bob Clegg" <bclegg@a...> on Tue, 10 Dec 2002 14:39:31 +1300
|
|
The read method goes false once you reach eof
Put it in a while loop. Every time you come round it automatically moves
onto the next record.
Hth
Bob
Dim strSQl As String
Dim cmdConn As SqlClient.SqlCommand
Dim cmdSource As SqlClient.SqlDataReader
Try
strSQl = " select Amount,supplier_id from Voucher" _
& " inner join batch on Voucher.batch_id= batch.id " _
& " where sts_code = '" & strScratchCardNo & "'" _
& " and voucher.active = 1 and date_used is null"
If cmdConn Is Nothing Then
cmdConn = New SqlClient.SqlCommand(strSQl, New
SqlClient.SqlConnection(mstrConnectionString))
cmdConn.Connection.Open()
cmdSource
cmdConn.ExecuteReader(CommandBehavior.CloseConnection)
End If
While cmdSource.Read
decValue = cmdSource.GetDecimal(0)
SupplierID = cmdSource.GetInt32(1)
wend
-----Original Message-----
From: John Tyson [mailto:jtyson@t...]
Sent: Tuesday, 10 December 2002 11:46 a.m.
To: aspx_beginners
Subject: [aspx_beginners] Re: determine if dr is empty
EOF is not a member of System.Data.SqlClient.SqlDataReader.
I have also tried If Not dr Is Nothing with no luck...
-----Original Message-----
From: Greg Griffiths [mailto:greg2@s...]
Sent: Monday, December 09, 2002 2:31 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: determine if dr is empty
try :
if (dr.EOF) then
' no results
else
' iterate through results
end if
At 13:25 09/12/02 -0800, you wrote:
>I have a page with two dropdown lists, one being dependent upon the
>selection in the other. I am not having a problem with populating them
>at page load, but when a change is made after page load. My two
>dropdown lists are hardware category and hardware sub category. When
>the category is changed, I pull a stored procedure that populates the
>second dropdown list with appropriate selections. Some categories do
>not have sub categories.
>
>What I am trying to do is print "N/A" as the selected item in the
>dropdownlist when no items are returned, or "Not selected" as the
>selected field when there are items.
>
>If Not (dr.Read()) Then
> ddlTypeSub.Items.Insert(0, "N/A")
> ddlTypeSub.SelectedIndex = 0
> ddlTypeSub.SelectedItem.Value = 0
> ddlTypeSub.SelectedItem.Text = "N/A"
> dr.Close()
>Else
> ddlTypeSub.Items.Insert(0, "not selected")
> ddlTypeSub.SelectedIndex = 0
> ddlTypeSub.SelectedItem.Value = 0
> ddlTypeSub.SelectedItem.Text = "not selected"
> dr.Close()
>End If
>
>However, the sub category box returns the selected item "N/A"
regardless
>of whether there are sub category items returned for the category
>selected. I tried placing "If Not page.IsPostBack" around the page
load
>calls that populate these dropdown lists, but that didn't make a
>difference. It's probably a dumb error somewhere - can anyone offer
any
>advice to lessen my mental anguish?
>
>Thanks,
>
>John
>
Message #5 by "Ken Schaefer" <ken@a...> on Tue, 10 Dec 2002 17:19:39 +1100
|
|
You could increment a counter variable.
If the counter is still 0, then add the empty "N/A" option
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "John Tyson" <jtyson@t...>
Subject: [aspx_beginners] determine if dr is empty
I have a page with two dropdown lists, one being dependent upon the
selection in the other. I am not having a problem with populating them
at page load, but when a change is made after page load. My two
dropdown lists are hardware category and hardware sub category. When
the category is changed, I pull a stored procedure that populates the
second dropdown list with appropriate selections. Some categories do
not have sub categories.
What I am trying to do is print "N/A" as the selected item in the
dropdownlist when no items are returned, or "Not selected" as the
selected field when there are items.
If Not (dr.Read()) Then
ddlTypeSub.Items.Insert(0, "N/A")
ddlTypeSub.SelectedIndex = 0
ddlTypeSub.SelectedItem.Value = 0
ddlTypeSub.SelectedItem.Text = "N/A"
dr.Close()
Else
ddlTypeSub.Items.Insert(0, "not selected")
ddlTypeSub.SelectedIndex = 0
ddlTypeSub.SelectedItem.Value = 0
ddlTypeSub.SelectedItem.Text = "not selected"
dr.Close()
End If
However, the sub category box returns the selected item "N/A" regardless
of whether there are sub category items returned for the category
selected. I tried placing "If Not page.IsPostBack" around the page load
calls that populate these dropdown lists, but that didn't make a
difference. It's probably a dumb error somewhere - can anyone offer any
advice to lessen my mental anguish?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message #6 by "John Tyson" <jtyson@t...> on Tue, 10 Dec 2002 08:22:46 -0800
|
|
Hi Bob,
I am a little confused. The method I used to establish the selectedItem
in the related dropdownlists (see below first message) worked in my page
load event: based on the selection in the first dropdownlist, the second
dropdownlist would either list selection items if available with
selectedItem =3D "Select from below" or "N/A" if no items were
available.
That is why I was sure my problem was a postback issue - I did not place
"If Not page.IsPostBack" around my page load events, and in my
sub_categoryChange I reset the second dropdownlist based on the
OnSelectedIndexChanged of the first dropdownlist if this is changed by
the user after the page is loaded.
>If Not (dr.Read()) Then
> ddlTypeSub.Items.Insert(0, "N/A")
> ddlTypeSub.SelectedIndex =3D 0
> ddlTypeSub.SelectedItem.Value =3D 0
> ddlTypeSub.SelectedItem.Text =3D "N/A"
> dr.Close()
>Else
> ddlTypeSub.Items.Insert(0, "not selected")
> ddlTypeSub.SelectedIndex =3D 0
> ddlTypeSub.SelectedItem.Value =3D 0
> ddlTypeSub.SelectedItem.Text =3D "not selected"
> dr.Close()
>End If
It's wierd, because the "N/A" selectedItem occurs regardless of whether
the dr returns records for the second dropdownlist or not. For most
selections in my first dropdownlist there are selectable items in the
second dropdownlist, but this procedure still plants "N/A" at the top as
the selectedItem.
So this really doesn't have anything to do with my page load procedure
and the issue of having the if not page.ispostback? It's just confusing
because this works as it should in the page load and puts N/A in the
dropdown when there are no secondary selections.
Thank you for your response.
John
-----Original Message-----
From: Bob Clegg [mailto:bclegg@a...]
Sent: Monday, December 09, 2002 5:40 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: determine if dr is empty
The read method goes false once you reach eof
Put it in a while loop. Every time you come round it automatically moves
onto the next record.
Hth
Bob
Dim strSQl As String
Dim cmdConn As SqlClient.SqlCommand
Dim cmdSource As SqlClient.SqlDataReader
Try
strSQl =3D " select Amount,supplier_id from Voucher" _
& " inner join batch on Voucher.batch_id=3D batch.id " _
& " where sts_code =3D '" & strScratchCardNo & "'" _
& " and voucher.active =3D 1 and date_used is null"
If cmdConn Is Nothing Then
cmdConn =3D New SqlClient.SqlCommand(strSQl, New
SqlClient.SqlConnection(mstrConnectionString))
cmdConn.Connection.Open()
cmdSource =3D
cmdConn.ExecuteReader(CommandBehavior.CloseConnection)
End If
While cmdSource.Read
decValue =3D cmdSource.GetDecimal(0)
SupplierID =3D cmdSource.GetInt32(1)
wend
-----Original Message-----
From: John Tyson [mailto:jtyson@t...]
Sent: Tuesday, 10 December 2002 11:46 a.m.
To: aspx_beginners
Subject: [aspx_beginners] Re: determine if dr is empty
EOF is not a member of System.Data.SqlClient.SqlDataReader.
I have also tried If Not dr Is Nothing with no luck...
-----Original Message-----
From: Greg Griffiths [mailto:greg2@s...]
Sent: Monday, December 09, 2002 2:31 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: determine if dr is empty
try :
if (dr.EOF) then
' no results
else
' iterate through results
end if
At 13:25 09/12/02 -0800, you wrote:
>I have a page with two dropdown lists, one being dependent upon the
>selection in the other. I am not having a problem with populating them
>at page load, but when a change is made after page load. My two
>dropdown lists are hardware category and hardware sub category. When
>the category is changed, I pull a stored procedure that populates the
>second dropdown list with appropriate selections. Some categories do
>not have sub categories.
>
>What I am trying to do is print "N/A" as the selected item in the
>dropdownlist when no items are returned, or "Not selected" as the
>selected field when there are items.
>
>If Not (dr.Read()) Then
> ddlTypeSub.Items.Insert(0, "N/A")
> ddlTypeSub.SelectedIndex =3D 0
> ddlTypeSub.SelectedItem.Value =3D 0
> ddlTypeSub.SelectedItem.Text =3D "N/A"
> dr.Close()
>Else
> ddlTypeSub.Items.Insert(0, "not selected")
> ddlTypeSub.SelectedIndex =3D 0
> ddlTypeSub.SelectedItem.Value =3D 0
> ddlTypeSub.SelectedItem.Text =3D "not selected"
> dr.Close()
>End If
>
>However, the sub category box returns the selected item "N/A"
regardless
>of whether there are sub category items returned for the category
>selected. I tried placing "If Not page.IsPostBack" around the page
load
>calls that populate these dropdown lists, but that didn't make a
>difference. It's probably a dumb error somewhere - can anyone offer
any
>advice to lessen my mental anguish?
>
>Thanks,
>
>John
>
|
|
 |