Forum
smartDBforms.NET for ASP.NET 2
 
 
Knowledge Base Forum
To post messages on the forum, you need to login first.
SearchForum Home
  Product Forums  smartDBforms.NET  Using Radiobutt...
 Using Radiobutton list in smartdbforms
 
 6/8/2010 2:58:40 AM
David
10 posts


Using Radiobutton list in smartdbforms
How do you create a radiobutton list that will bind to a field already in an insert mode smartdbform??
 6/8/2010 9:09:44 AM
Adillis Support
43 posts
adillis.com


Re: Using Radiobutton list in smartdbforms

Hi David


The easiest way to have radiobutton list is to create it inside SmartDBView and to two-way databind its SelectedValue property to the proper db field. The radiobutton list items should the items which can be inserted. The value of the items will be the actual value that will be inserted in the db field when the SmartDBView form is saved.


For example the following radiobutton list is bound to an integer db field SupplierID which and can insert values from 1 to 7.

<asp:RadioButtonList ID="radioSupplier" runat="server" SelectedValue='<%# Bind("SupplierID") %>'

Enabled='<%# !Container.IsReadOnlyMode %>'>

<asp:ListItem Value="1">Exotic Liquids</asp:ListItem>

<asp:ListItem Value="2">New Orleans Cajun Delights</asp:ListItem>

<asp:ListItem Value="3">Grandma Kelly's Homestead</asp:ListItem>

<asp:ListItem Value="4">Tokyo Traders</asp:ListItem>

<asp:ListItem Value="5">Cooperativa de Quesos 'Las Cabras'</asp:ListItem>

<asp:ListItem Value="6">Mayumi's</asp:ListItem>

<asp:ListItem Value="7">Pavlova, Ltd.</asp:ListItem>

</asp:RadioButtonList>


If you have any other questions, we will be more than happy to help you.

Best wishes,

Adillis Support

Adillis - IT solutions http://adillis.com

 6/8/2010 11:30:12 PM
David
10 posts


Re: Using Radiobutton list in smartdbforms

Here is the code and error I get:

<asp:RadioButtonList ID="RadioButtonList1" runat="server"

RepeatDirection="Horizontal" SelectedValue='<%# Bind("CDFQ1A") %>'>

<asp:ListItem Value="5"></asp:ListItem>

<asp:ListItem Value="4"></asp:ListItem>

<asp:ListItem Value="3"></asp:ListItem>

<asp:ListItem Value="2"></asp:ListItem>

<asp:ListItem Value="1"></asp:ListItem>

</asp:RadioButtonList>

 

'RadioButtonList1' has a SelectedValue which is invalid because it does not exist in the list of items.
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: 'RadioButtonList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I seem to get this everytime i try to use a standard control inside VWS2008???
 6/8/2010 11:31:32 PM
David
10 posts


Re: Using Radiobutton list in smartdbforms
The radiolistbox code is in a smartdbform and setup using the wizard
 6/9/2010 9:27:11 AM
Adillis Support
43 posts
adillis.com


Re: Using Radiobutton list in smartdbforms

Hi David,

When in Insert mode the children are databound against default values. In this case the default value for integer db field will be 0. The error appears because during initial databinding the CDFQ1A field has value 0 and the RadioButtonList does not have ListItem with Value 0.

You can resolve this in one of the following ways:

  • You can add one more ListItem with Value 0. This will be the initially selected ListItem

  • You can change the default value of CDFQ1A during Insert. This can be done in the following way – Open the SmartDataSource for the form. Select the Insert tab. In the Parameters list click the CDFQ1A parameter. On the right-hand side you will see DefaultValue field. Put the value you desire, for example 1 – this will select the last ListItem in your example.

  • The last way requires one line of code. Remove the SelectedValue='<%# Bind("CDFQ1A") %> expression from your RadioButtonList. In this way the SelectedValue attribute will not be databound and there will be no exception. But now the value is also not extracted during save time. You should put code to extract the selected value during save. Create event handler for the SmartDBView.ValuesExtracted event. In the event handler put the following code to extract the selected value:
    protected void SmartDBView1_ValuesExtracted(SmartDBView sender, SmartDBViewExtractedArgs e)
    {
      
    e.Values["CDFQ1A"] = RadioButtonList1.SelectedValue;
    }

If you have any other questions, we will be more than happy to help you.
Best wishes,
Adillis Support
Adillis - IT solutions http://adillis.com

  Product Forums  smartDBforms.NET  Using Radiobutt...
Copyright 2006-2010 Adillis Terms Of Use Feedback Contact Us