dotNetDave
April 28th, 2004, 06:18 PM
Problem: Unsure how to specifically select a value in a checkbox.
Code
Sub Check_Clicked(sender As Object, e As EventArgs)
Dim i As Integer
For i = 0 To cblAttribs.Items.Count - 1
If cblAttribs.Items(0).Selected Then
panelDurabilityBonus.Visible = true
Else if cblAttribs.Items(0).Selected = False
panelDurabilityBonus.Visible = false
End If
Next
End Sub
The question I have is related to this line of code:
If cblAttribs.Items(0).Selected Then
and this one
Else if cblAttribs.Items(0).Selected = False
What would I need to supply to specifically say, for example, "I want selection 'bob'"?
I tried
If cblAttribs.Items(bob).Selected Then
however that only returned an error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'bob' is not declared.
Source Error:
Line 154: Dim i As Integer
Line 155: For i = 0 To cblAttribs.Items.Count - 1
Line 156: If cblAttribs.Items(bob).Selected Then
Line 157: panelDurabilityBonus.Visible = true
Line 158: Else if cblAttribs.Items(bob).Selected = False
The values for the selection are already setup in my list box, the asp code for the listbox is as follows:
<asp:CheckBoxList CssClass="style14" ID="cblAttribs" RepeatColumns="3" RepeatDirection="vertical" RepeatLayout="table" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Check_Clicked">
<asp:ListItem value="chkDurabilityBonus">Durability Bonus</asp:ListItem>
<asp:ListItem value="chkHitDispel">Hit Dispel</asp:ListItem>
<asp:ListItem value="chkHitPhysicalArea">Hit Physical Area</asp:ListItem>
<asp:ListItem value="chkHitFireArea">Hit Fire Area</asp:ListItem>
<asp:ListItem value="chkHitColdArea">Hit Cold Area</asp:ListItem>
<asp:ListItem value="chkHitPoisonArea">Hit Poison Area</asp:ListItem>
<asp:ListItem value="chkHitEnergyArea">Hit Energy Area</asp:ListItem>
<asp:ListItem value="chkHitFireball">Hit Fireball</asp:ListItem>
<asp:ListItem value="chkHitHarm">Hit Harm</asp:ListItem>
<asp:ListItem value="chkHitLeechHits">Hit Leech Hits</asp:ListItem>
<asp:ListItem value="chkHitLeechMana">Hit Leech Mana</asp:ListItem>
<asp:ListItem value="chkHitLeechStamina">Hit Leech Stamina</asp:ListItem>
<asp:ListItem value="chkHitLightning">Hit Lightning</asp:ListItem>
<asp:ListItem value="chkHitLowerAttack">Hit Lower Attack</asp:ListItem>
<asp:ListItem value="chkHitLowerDefend">Hit Lower Defense</asp:ListItem>
<asp:ListItem value="chkHitMagicArrow">Hit Magic Arrow</asp:ListItem>
<asp:ListItem value="chkLowerStatReq">Lower Stat Requirement</asp:ListItem>
<asp:ListItem value="chkMageWeapon">Mage Weapon</asp:ListItem>
<asp:ListItem value="chkResistPhysicalBonus">Resist Physical Bonus</asp:ListItem>
<asp:ListItem value="chkResistFireBonus">Resist Fire Bonus</asp:ListItem>
<asp:ListItem value="chkResistColdBonus">Resist Cold Bonus</asp:ListItem>
<asp:ListItem value="chkResistEnergyBonus">Resist Energy Bonus</asp:ListItem>
<asp:ListItem value="chkResistPoisonBonus">Resist Poison Bonus</asp:ListItem>
<asp:ListItem value="chkSelfRepair">Self Repair</asp:ListItem>
<asp:ListItem value="chkUseBestSkill">Use Best Skill</asp:ListItem>
</asp:CheckBoxList>
Any help would be greatly appreciated! Thanks!
Code
Sub Check_Clicked(sender As Object, e As EventArgs)
Dim i As Integer
For i = 0 To cblAttribs.Items.Count - 1
If cblAttribs.Items(0).Selected Then
panelDurabilityBonus.Visible = true
Else if cblAttribs.Items(0).Selected = False
panelDurabilityBonus.Visible = false
End If
Next
End Sub
The question I have is related to this line of code:
If cblAttribs.Items(0).Selected Then
and this one
Else if cblAttribs.Items(0).Selected = False
What would I need to supply to specifically say, for example, "I want selection 'bob'"?
I tried
If cblAttribs.Items(bob).Selected Then
however that only returned an error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'bob' is not declared.
Source Error:
Line 154: Dim i As Integer
Line 155: For i = 0 To cblAttribs.Items.Count - 1
Line 156: If cblAttribs.Items(bob).Selected Then
Line 157: panelDurabilityBonus.Visible = true
Line 158: Else if cblAttribs.Items(bob).Selected = False
The values for the selection are already setup in my list box, the asp code for the listbox is as follows:
<asp:CheckBoxList CssClass="style14" ID="cblAttribs" RepeatColumns="3" RepeatDirection="vertical" RepeatLayout="table" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Check_Clicked">
<asp:ListItem value="chkDurabilityBonus">Durability Bonus</asp:ListItem>
<asp:ListItem value="chkHitDispel">Hit Dispel</asp:ListItem>
<asp:ListItem value="chkHitPhysicalArea">Hit Physical Area</asp:ListItem>
<asp:ListItem value="chkHitFireArea">Hit Fire Area</asp:ListItem>
<asp:ListItem value="chkHitColdArea">Hit Cold Area</asp:ListItem>
<asp:ListItem value="chkHitPoisonArea">Hit Poison Area</asp:ListItem>
<asp:ListItem value="chkHitEnergyArea">Hit Energy Area</asp:ListItem>
<asp:ListItem value="chkHitFireball">Hit Fireball</asp:ListItem>
<asp:ListItem value="chkHitHarm">Hit Harm</asp:ListItem>
<asp:ListItem value="chkHitLeechHits">Hit Leech Hits</asp:ListItem>
<asp:ListItem value="chkHitLeechMana">Hit Leech Mana</asp:ListItem>
<asp:ListItem value="chkHitLeechStamina">Hit Leech Stamina</asp:ListItem>
<asp:ListItem value="chkHitLightning">Hit Lightning</asp:ListItem>
<asp:ListItem value="chkHitLowerAttack">Hit Lower Attack</asp:ListItem>
<asp:ListItem value="chkHitLowerDefend">Hit Lower Defense</asp:ListItem>
<asp:ListItem value="chkHitMagicArrow">Hit Magic Arrow</asp:ListItem>
<asp:ListItem value="chkLowerStatReq">Lower Stat Requirement</asp:ListItem>
<asp:ListItem value="chkMageWeapon">Mage Weapon</asp:ListItem>
<asp:ListItem value="chkResistPhysicalBonus">Resist Physical Bonus</asp:ListItem>
<asp:ListItem value="chkResistFireBonus">Resist Fire Bonus</asp:ListItem>
<asp:ListItem value="chkResistColdBonus">Resist Cold Bonus</asp:ListItem>
<asp:ListItem value="chkResistEnergyBonus">Resist Energy Bonus</asp:ListItem>
<asp:ListItem value="chkResistPoisonBonus">Resist Poison Bonus</asp:ListItem>
<asp:ListItem value="chkSelfRepair">Self Repair</asp:ListItem>
<asp:ListItem value="chkUseBestSkill">Use Best Skill</asp:ListItem>
</asp:CheckBoxList>
Any help would be greatly appreciated! Thanks!