Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re:thread855-1483475 checkboxlist

Status
Not open for further replies.

aspgasket

Programmer
Feb 16, 2010
3
US
I am trying to following the code example thats in a old thread for checkboxlist and ran into the following error.
Not sure whats going wrong.

public void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
CheckBoxList cbl1 = (CheckBoxList)this.FormView1.FindControl("Review");
if (cbl1 != null)
{
SqlDataSource1.UpdateParameters["Review"].DefaultValue = cbl1.SelectedValue;
//assign other parameters
SqlDataSource1.Update();
}
}



Aspx

Review:

<asp:CheckBoxList ID="Review" runat="server" SelectedValue='<%#Bind("Review") %>'>
<asp:ListItem Value="a123" Text="a123"></asp:ListItem>
<asp:ListItem Value="b1234" Text="b1234"></asp:ListItem>
<asp:ListItem Value="c1235" Text="c1235"></asp:ListItem>
<asp:ListItem Value="d1236" Text="d1236"></asp:ListItem>
<asp:ListItem Value="e1237" Text="e1237"></asp:ListItem>
<asp:ListItem Value="f1238" Text="f1238"></asp:ListItem>
<asp:ListItem Value="g1239" Text="g1239"></asp:ListItem>
<asp:ListItem Value="h1230" Text="h1230"></asp:ListItem>
<asp:ListItem Value="i1231" Text="i1231"></asp:ListItem>
</asp:CheckBoxList>



Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'cbl1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

 
<asp:CheckBoxList ID="Review" runat="server" SelectedValue='<%#Bind("Review") %>'>
<asp:ListItem Value="a123" Text="a123"></asp:ListItem>
<asp:ListItem Value="b1234" Text="b1234"></asp:ListItem>
<asp:ListItem Value="c1235" Text="c1235"></asp:ListItem>
<asp:ListItem Value="d1236" Text="d1236"></asp:ListItem>
<asp:ListItem Value="e1237" Text="e1237"></asp:ListItem>
<asp:ListItem Value="f1238" Text="f1238"></asp:ListItem>
<asp:ListItem Value="g1239" Text="g1239"></asp:ListItem>
<asp:ListItem Value="h1230" Text="h1230"></asp:ListItem>
<asp:ListItem Value="i1231" Text="i1231"></asp:ListItem>
</asp:CheckBoxList>
 
I think this is a timing issue. the checkboxlist items may not have been populated with items at the time you are trying to access the selected value.

to confirm check the items collection before calling selectedvalue.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
I was able to get rid of the error message by adding a "" within the listitem
<asp:ListItem Text="Check all that apply" Value="" />
But, now when I search on the record number it only returns one item, instead of multi items that were check.

should I be doing something with the search button?
.........
<asp:TextBox id="nbrRN" runat="server" />
<asp:button id="btnSubmit" Text="Enter # to Search" OnClick="btnSubmit_Click" Runat="server" />

.........
<SelectParameters>
<asp:ControlParameter
Name="RecN"
ControlID="nbrRN"
PropertyName="Text"/>
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top