Codeaddict7423
asked on
required field validator for databound dropdownlist
Hello,
I have a web application built using VS 2005 and C#. There is a dropdown control bound to a database table using a dataset as follows:
-----------
<asp:DropDownList ID="ddl_ICLU_Specify" runat="server" SelectedValue='<%# Bind("ICLU_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_ICLU" DataTextField="LU_CODE_Des c" DataValueField="LU_CODE_De sc" AppendDataBoundItems="true ">
</asp:DropDownList>
<asp:SqlDataSource id="ds_LU_ICLU" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon nectionStr ing %>" SelectCommand="SELECT [LU_CODE_Desc] FROM [RLUIS_LU]"></asp:SqlDataS ource>
<span style="color:Red">*</span>
<asp:RequiredFieldValidato r ID="RFV_ICLU_Specify" runat="server" ErrorMessage="Please Select" ControlToValidate="ddl_ICL U_Specify" InitialValue=" " Display="dynamic" Enabled="false"></asp:Requ iredFieldV alidator>
--------
I am attempting to validate that if the user has the web application display "Please Select" on the ddl control, the database entry is a "null" rather than "Please Select"
Right now, the RequiredFieldValidator does not seem to validate against the ddl control's data source, where the first choice is "Please Select"
Again, I just want to have the code enter a " " value into the database table rather than "Please Select"
Please help...
I have a web application built using VS 2005 and C#. There is a dropdown control bound to a database table using a dataset as follows:
-----------
<asp:DropDownList ID="ddl_ICLU_Specify" runat="server" SelectedValue='<%# Bind("ICLU_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_ICLU" DataTextField="LU_CODE_Des
</asp:DropDownList>
<asp:SqlDataSource id="ds_LU_ICLU" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon
<span style="color:Red">*</span>
<asp:RequiredFieldValidato
--------
I am attempting to validate that if the user has the web application display "Please Select" on the ddl control, the database entry is a "null" rather than "Please Select"
Right now, the RequiredFieldValidator does not seem to validate against the ddl control's data source, where the first choice is "Please Select"
Again, I just want to have the code enter a " " value into the database table rather than "Please Select"
Please help...
If you have first choice available as "Please select" then youcan put it as initial value in Required field validator as below:
<asp:RequiredFieldValidato r ID="RFV_ICLU_Specify" runat="server" ErrorMessage="Please Select" ControlToValidate="ddl_ICL U_Specify" InitialValue="Please Select " Display="dynamic" Enabled="false"></asp:Requ iredFieldV alidator>
else
After binding datasource to the Dropdownlist you can insert "Please Select" as first item and then set the Intial value in Required field validator as mentioned above. You can insert item as below :
ddl_ICLU_Specify.Items.Ins ert(0, new ListItem("Please Select","Please Select");
Hope this will work for you.
Regards,
Ram
<asp:RequiredFieldValidato
else
After binding datasource to the Dropdownlist you can insert "Please Select" as first item and then set the Intial value in Required field validator as mentioned above. You can insert item as below :
ddl_ICLU_Specify.Items.Ins
Hope this will work for you.
Regards,
Ram
ASKER
ramkisan,
Thank you for the quick reply. I implemented your suggestion and indeed, now the validator works for the ddl data source and does not submit when "please select" is displayed as a choice.
However, the choice "please select" is still being added to the database table. Now, i'd like to know how to code your suggestion such that instead of "please select", there is a " " value added to the database table.
Thank you in advance.
Thank you for the quick reply. I implemented your suggestion and indeed, now the validator works for the ddl data source and does not submit when "please select" is displayed as a choice.
However, the choice "please select" is still being added to the database table. Now, i'd like to know how to code your suggestion such that instead of "please select", there is a " " value added to the database table.
Thank you in advance.
For this purpose you can set value for please select item as " " and set the initial value of the Required filed validator as " " too, so that whenever you select "Please Select" it will put its value as " " .
Hope this will help you.
Regards,
Ram
Hope this will help you.
Regards,
Ram
ASKER
ramkisan,
Thank yoiu for your quick reply. i can see how to change the value of the requiredfieldvalidator to " " but i'm a bit confused in how to 'set value for please select item as " " '
I'm pulling the values for the ddl from a sql database table. in this table, i have a column called LU_Desc. this column has the description of the text displayed as choices in the ddl_ICLU_Specify. How can I set this value as " " and still show "please select"
Thank you in advance
Thank yoiu for your quick reply. i can see how to change the value of the requiredfieldvalidator to " " but i'm a bit confused in how to 'set value for please select item as " " '
I'm pulling the values for the ddl from a sql database table. in this table, i have a column called LU_Desc. this column has the description of the text displayed as choices in the ddl_ICLU_Specify. How can I set this value as " " and still show "please select"
Thank you in advance
ddl_ICLU_Specify.Items.Ins ert(0, new ListItem("Please Select"," ");
By this you can add item "Please Select" with " " value.
Still u r not able to do that can you please share urn code?
I am available for next 15 mins.
Regards,
Ram
By this you can add item "Please Select" with " " value.
Still u r not able to do that can you please share urn code?
I am available for next 15 mins.
Regards,
Ram
ASKER
ramkisan,
Below, please find my code.
----------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GIS Land Use Test Default</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></s cript>
<!-- This function takes an array of the ddl Ids and set the selected index of the ddl to 0 i.e. the first item ("Please Select")-->
<script type="text/JavaScript">
function toggle(chb,target,validato rsArray,dd larray)
{
if (chb.checked == false) {
for (i = 0; i < ddlarray.length; i++) {
var vid = $("[id$='_" + ddlarray[i] + "']").attr('id');
var val = document.getElementById(vi d);
val.selectedIndex = 0;
}
// window.location.reload();
}
obj=(document.all) ? document.all[target] : document.getElementById(ta rget);
obj.style.display = (obj.style.display == 'none') ? 'inline' : 'none';
var enable = true;
if (obj.style.display == 'none') {
enable = false;
}
var i = 0;
for (i = 0; i < validatorsArray.length; i++) {
var vid = $("[id$='_" + validatorsArray[i] + "']").attr('id');
val = document.getElementById(vi d)
ValidatorEnable(val, enable);
}
}
function textboxMultilineMaxNumber( txt,maxLen ){
try{
if(txt.value.length > (maxLen-1))
return false;
}catch(e){
}
}
</script>
<!--after this, the function call from the textbox (<input type="checkbox" id="chk_ICLU" name="chk_ICLU" onclick="toggle(this,'ther ow',['RFV_ ICLU_Corre ction','RF V_ICLU_Spe cify'],['d dl_ICLU_Co rrection', 'ddl_ICLU_ Specify'] )" /> takes the array of the ddls and reindexes them to 0 so when the checkbox is de-selected (chb.checked == false), it fires first and the code that opens up the table row adn displays the panel (panel1, panel2, panel3) gives the user choices.
-->
</head>
<body style="background-color:#1 c2a09" >
<form id="form1" runat="server">
<div style="text-align:left">
<img src="images/logo.jpg" alt="logo"/>
<table width="80%" cellpadding="5" cellspacing="0" border="1" bordercolor="#1c2a09" style="background-color:#F FFFFF;bord er: solid; border-color: #1c2a09; height: 500px;">
<tr><td><h2 style="background-color:#F FFFFF;font -size:14pt "> Feedback Form</h2>
Fields marked with an <span style="color:Red;backgroun d-color:#F FFFFF">*</ span> are required.
<br />
</td></tr>
<tr>
<td style="width:100%" valign="top" align="left">
<asp:FormView Width="100%" ID="FormView1" runat="server" DataKeyNames="INPUTID" DataSourceID="ds_RLUIS1" DefaultMode="Insert" Font-Names="Arial" Font-Size="10pt" AllowPaging="false" BackColor="white" BorderColor="white" BorderWidth="0px" CellPadding="2" >
<InsertItemTemplate>
<table cellpadding="1" cellspacing="0" border="0">
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#F0F0F0;f ont-weight :bold "><asp:Label ID="INPUTIDLabel" runat="server" Text="Parcel ID:"></asp:Label> &nb sp; < /td>
<td style="width:70%;backgroun d-color:#F 0F0F0;font -weight:bo ld;font-si ze:10pt">
<asp:TextBox ID="ParcelIDTextBox" runat="server" style="font-weight:bold;ba ckground-c olor:#F0F0 F0" Text='<%# Bind("ParcelID") %>' ReadOnly="true" BorderWidth="0"></asp:Text Box>
<br /><br />
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%"> &nb sp;</td>
<td style="text-align: left; white-space: nowrap; width: 25%"><span>
<span style="font-weight:normal; color:Red" > Tell us what you think needs to be changed or included: (check all that apply) </span>
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%" valign="top"><asp:Label ID="Label1" runat="server" Text="Incorrect Current Land Use"></asp:Label> &nb sp; & nbsp;</td>
<td style="text-align: left; white-space: nowrap; width: 25%">
<input type="checkbox" id="chk_ICLU" name="chk_ICLU" onclick="toggle(this,'ther ow',['RFV_ ICLU_Corre ction','RF V_ICLU_Spe cify'],['d dl_ICLU_Co rrection', 'ddl_ICLU_ Specify'] )" />
<!--Incorrect Current Land Use Panel -->
<div id="therow" style="display:none">
<asp:Panel ID="Panel1" runat="server" Visible="true">
<table cellpadding="5" cellspacing="0" border="0" bgcolor="#F0F0F0">
<tr>
<td style="width:30%; text-align:left; vertical-align:top"><asp:L abel ID="Label4" runat="server" Text="Basis for Correction:"></asp:Label>< br /></td>
<td style="width:70%; text-align:left; vertical-align:top">
<asp:DropDownList ID="ddl_ICLU_Correction" runat="server" SelectedValue='<%# Bind("ICLU_Correction") %>' AutoPostBack="false">
<asp:ListItem Value=" " Text="Please Select" Selected="true">Please Select</asp:ListItem>
<asp:ListItem Value="Inconsistent with Imagery" Text="Inconsistent with Imagery">Inconsistent with Imagery</asp:ListItem>
<asp:ListItem Value="Personal Knowledge of Area" Text="Personal Knowledge of Area">Personal Knowledge of Area &nbs p;</asp:Li stItem>
</asp:DropDownList> < span style="color:Red">*</span>
<asp:RequiredFieldValidato r ID="RFV_ICLU_Correction" runat="server" ErrorMessage="Please Select" ControlToValidate="ddl_ICL U_Correcti on" InitialValue=" " Display="dynamic" Enabled="false"></asp:Requ iredFieldV alidator>
</td>
</tr>
<tr>
<td style="width:30%; text-align:left; vertical-align:top"><asp:L abel ID="Label6" runat="server" Text="Specify Correct Current Land Use:"></asp:Label> <b r /> </td>
<td style="width:70%; text-align:left; vertical-align:top">
<asp:DropDownList ID="ddl_ICLU_Specify" runat="server" SelectedValue='<%# Bind("ICLU_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_ICLU" DataTextField="LU_CODE_Des c" DataValueField="LU_CODE_De sc" AppendDataBoundItems="true " CausesValidation="true">
</asp:DropDownList>
<asp:SqlDataSource id="ds_LU_ICLU" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon nectionStr ing %>" SelectCommand="SELECT [LU_CODE_Desc] FROM [RLUIS_LU]"></asp:SqlDataS ource>
<span style="color:Red">*</span>
<asp:RequiredFieldValidato r ID="RFV_ICLU_Specify" runat="server" ErrorMessage="Please Select" ControlToValidate="ddl_ICL U_Specify" InitialValue=" " Display="dynamic" Enabled="false"></asp:Requ iredFieldV alidator>
</td>
</tr>
</table>
</asp:Panel>
</div>
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%; background-color:#FFFFFF" valign="top"><asp:Label ID="Label2" runat="server" Text="Incorrect Future Land Use"></asp:Label> &nb sp; & nbsp;</td>
<td style="text-align: left; white-space: nowrap; width: 25%">
<input type="checkbox" id="chk_IFLU" name="chk_IFLU" onclick="toggle(this,'ther ow02',['Re quiredFiel dValidator _IFLU_Spec ify'],['dd l_IFLU_Spe cify'] )" />
<!--Incorrect Future Land Use Panel -->
<div id="therow02" style="display:none">
<asp:Panel ID="Panel2" runat="server">
<table cellpadding="5" cellspacing="0" border="0" bgcolor="#F0F0F0">
<tr>
<td style="width:30%"><asp:Lab el ID="Label5" runat="server" Text="Specify Correct Future Land Use:"></asp:Label> &n bsp;<br /> </td>
<td style="width:70%">
<asp:DropDownList ID="ddl_IFLU_Specify" runat="server" SelectedValue='<%# Bind("IFLU_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_IFLU" DataTextField="LU_CODE_Des c" DataValueField="LU_CODE_De sc"></asp: DropDownLi st>
<asp:SqlDataSource ID="ds_LU_IFLU" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon nectionStr ing %>" SelectCommand="SELECT [LU_CODE_Desc] FROM [RLUIS_LU]"></asp:SqlDataS ource>
<span style="color:Red">*</span>
<asp:RequiredFieldValidato r ID="RequiredFieldValidator _IFLU_Spec ify" runat="server" ErrorMessage="Please Select" ControlToValidate="ddl_IFL U_Specify" InitialValue="Please Select" Display="dynamic" Enabled="false"></asp:Requ iredFieldV alidator>
</td>
</tr>
</table>
</asp:Panel>
</div>
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%" valign="top"><asp:Label ID="Label3" runat="server" Text="Future Development At This Location"></asp:Label>&nbs p; &n bsp; </td>
<td style="text-align: left; white-space: nowrap; width: 25%" valign="top">
<input type="checkbox" id="chk_FDATL" name="chk_FDATL" onclick="toggle(this,'ther ow03',['Re quiredFiel dValidator _FDATL_Spe cify'],['d dl_FDATL_S pecify'] )" />
<div id="therow03" style="display:none">
<!--Future Development At This Location Panel -->
<asp:Panel ID="Panel3" runat="server">
<table cellpadding="5" cellspacing="0" border="0" bgcolor="#F0F0F0">
<tr>
<td style="width:30%; text-align:left; vertical-align:top"><asp:L abel ID="Label8" runat="server" Text="Specify Future Land Use:"></asp:Label> &n bsp; &nbs p; &n bsp; &nbs p; &n bsp; <br /> </td>
<td style="width:70%; text-align:left; vertical-align:top">
<asp:DropDownList ID="ddl_FDATL_Specify" runat="server" SelectedValue='<%# Bind("FDATL_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_FDATL" DataTextField="LU_CODE_Des c" DataValueField="LU_CODE_De sc">
</asp:DropDownList>
<asp:SqlDataSource ID="ds_LU_FDATL" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon nectionStr ing %>"
SelectCommand="SELECT [LU_CODE_Desc] FROM [RLUIS_LU]"></asp:SqlDataS ource>
<span style="color:Red">*</span>
<asp:RequiredFieldValidato r ID="RequiredFieldValidator _FDATL_Spe cify" runat="server" ErrorMessage="Please Select" ControlToValidate="ddl_FDA TL_Specify " InitialValue="Please Select" Display="dynamic" Enabled="false"></asp:Requ iredFieldV alidator>
</td>
</tr>
</table>
<table cellpadding="5" cellspacing="0" border="0" width="100%" bgcolor="#F0F0F0">
<tr>
<td colspan="2" valign="top" align="left" style="width:100%"> </td>
</tr>
<tr>
<td colspan="2" style="width:100%; text-align:left; vertical-align:top">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td style="width:15%; text-align:left; vertical-align:top"><asp:L abel ID="Label11" runat="server" Text="Source"></asp:Label> </td>
<td style="width:85%; text-align:left; vertical-align:top"> <asp:TextB ox ID="FDATL_SourceTextBox" runat="server" onkeypress="return textboxMultilineMaxNumber( this,254)" Rows="4" Columns="41" TextMode="MultiLine" Text='<%# Bind("FDATL_Source") %>'></asp:TextBox>
<asp:RegularExpressionVali dator ID="RegularExpressionValid ator3" runat="server" ControlToValidate="FDATL_S ourceTextB ox"
Display="Dynamic" ErrorMessage="Please limit to 254 characters or less."
ValidationExpression="[\s\ S]{1,255}" ></asp:Reg ularExpres sionValida tor></td>
</tr>
</table>
</td>
</tr>
</table><br />
</asp:Panel>
</div>
</td>
</tr>
<!--Name and email textboxes -->
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#FFFFFF "><asp:Label ID="Label7" runat="server" Text="Comments & <br /> Additional Information: "></asp: Label>&nbs p; &n bsp;</td>
<td style="width:70%; text-align:left; vertical-align:top">
<asp:TextBox ID="Comments" runat="server" TextMode="MultiLine" Width="55%" onkeypress="return textboxMultilineMaxNumber( this,254)" Columns="66" Rows="4" ToolTip="Please include any additional information (eg.g. name of development)" Text='<%# Bind("Comments") %>'> </asp:TextBox>
<asp:RegularExpressionVali dator ID="RegularExpressionValid ator1" runat="server" ControlToValidate="Comment s"
Display="Dynamic" ErrorMessage="Please limit to 254 characters or less."
ValidationExpression="[\s\ S]{1,255}" ></asp:Reg ularExpres sionValida tor>
</td>
</tr>
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#FFFFFF ">Your Name:<asp:Label ID="Label12" runat="server" AssociatedControlID="Name" ></asp:Lab el> & nbsp;  ; </td>
<td style="width:70%; text-align:left; vertical-align:top">
<asp:TextBox ID="Name" Width="55%" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox> <s pan style="color: red"> * </span>
<asp:RequiredFieldValidato r ID="RequiredFieldValidator _Name" runat="server" ControlToValidate="Name" Display="Dynamic" ErrorMessage="Name is required" EnableClientScript="true" SetFocusOnError="true"></a sp:Require dFieldVali dator>
</td>
</tr>
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#FFFFFF "><asp:Label ID="Label13" runat="server" Text="Email:" AssociatedControlID="Email "></asp:La bel> &nbs p;</td>
<td style="width:70%; text-align:left; vertical-align:top">
<asp:TextBox ID="Email" Width="55%" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox> <s pan style="color: red"> * </span>
<asp:RequiredFieldValidato r ID="RequiredFieldValidator _Email" runat="server" ControlToValidate="Email" Display="Dynamic" ErrorMessage="Email is required" EnableClientScript="true" SetFocusOnError="true"></a sp:Require dFieldVali dator>
<asp:RegularExpressionVali dator ID="RegularExpressionValid ator2" runat="server"
ControlToValidate="Email" ValidationExpression="^[a- zA-Z][\w\. -]*[a-zA-Z 0-9]@[a-zA -Z0-9][\w\ .-]*[a-zA- Z0-9]\.[a- zA-Z][a-zA -Z\.]*[a-z A-Z]$" Display="Dynamic" ErrorMessage="Please Enter a Valid e-mail"></asp:RegularExpre ssionValid ator>
</td>
</tr>
<tr>
<td style="width:30%; text-align:left; vertical-align:top; background-color:#ffffff "> </td>
<td style="width:70%; text-align:left; vertical-align:top"><br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Submit"> </asp:Button> & nbsp;
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:Button>
<br /> <br />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
</td>
</tr>
</table>
<asp:SqlDataSource ID="ds_RLUIS1" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon nectionStr ing %>" OnInserted="SqlDataSource1 _Inserted"
InsertCommand="INSERT INTO [RLUIS] ([ParcelID], [ICLU_Correction], [ICLU_Specify], [IFLU_Specify], [FDATL_Specify], [FDATL_Source], [Comments], [Name], [Email]) VALUES (@ParcelID, @ICLU_Correction, @ICLU_Specify, @IFLU_Specify, @FDATL_Specify, @FDATL_Source, @Comments, @Name, @Email)"
SelectCommand="SELECT [INPUTID], [ParcelID], [ICLU_Correction], [ICLU_Specify], [IFLU_Specify], [FDATL_Specify], [FDATL_Source], [Comments], [Name], [Email] FROM [RLUIS]"
UpdateCommand="UPDATE [RLUIS] SET [ParcelID] = @ParcelID, [ICLU_Correction] = @ICLU_Correction, [ICLU_Specify] = @ICLU_Specify, [IFLU_Specify] = @IFLU_Specify, [FDATL_Specify] = @FDATL_Specify, [FDATL_Source] = @FDATL_Source, [Comments] = @Comments, [Name] = @Name, [Email] = @Email WHERE [INPUTID] = @INPUTID">
<UpdateParameters>
<asp:Parameter Name="ParcelID" Type="String" />
<asp:Parameter Name="ICLU_Correction" Type="String" />
<asp:Parameter Name="ICLU_Specify" Type="String" />
<asp:Parameter Name="IFLU_Specify" Type="String" />
<asp:Parameter Name="FDATL_Specify" Type="String" />
<asp:Parameter Name="FDATL_Source" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="INPUTID" Type="Int16" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ParcelID" Type="String" />
<asp:Parameter Name="ICLU_Correction" Type="String" />
<asp:Parameter Name="ICLU_Specify" Type="String" />
<asp:Parameter Name="IFLU_Specify" Type="String" />
<asp:Parameter Name="FDATL_Specify" Type="String" />
<asp:Parameter Name="FDATL_Source" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
---------
Thank you.
Below, please find my code.
----------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GIS Land Use Test Default</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></s
<!-- This function takes an array of the ddl Ids and set the selected index of the ddl to 0 i.e. the first item ("Please Select")-->
<script type="text/JavaScript">
function toggle(chb,target,validato
{
if (chb.checked == false) {
for (i = 0; i < ddlarray.length; i++) {
var vid = $("[id$='_" + ddlarray[i] + "']").attr('id');
var val = document.getElementById(vi
val.selectedIndex = 0;
}
// window.location.reload();
}
obj=(document.all) ? document.all[target] : document.getElementById(ta
obj.style.display = (obj.style.display == 'none') ? 'inline' : 'none';
var enable = true;
if (obj.style.display == 'none') {
enable = false;
}
var i = 0;
for (i = 0; i < validatorsArray.length; i++) {
var vid = $("[id$='_" + validatorsArray[i] + "']").attr('id');
val = document.getElementById(vi
ValidatorEnable(val, enable);
}
}
function textboxMultilineMaxNumber(
try{
if(txt.value.length > (maxLen-1))
return false;
}catch(e){
}
}
</script>
<!--after this, the function call from the textbox (<input type="checkbox" id="chk_ICLU" name="chk_ICLU" onclick="toggle(this,'ther
-->
</head>
<body style="background-color:#1
<form id="form1" runat="server">
<div style="text-align:left">
<img src="images/logo.jpg" alt="logo"/>
<table width="80%" cellpadding="5" cellspacing="0" border="1" bordercolor="#1c2a09" style="background-color:#F
<tr><td><h2 style="background-color:#F
Fields marked with an <span style="color:Red;backgroun
<br />
</td></tr>
<tr>
<td style="width:100%" valign="top" align="left">
<asp:FormView Width="100%" ID="FormView1" runat="server" DataKeyNames="INPUTID" DataSourceID="ds_RLUIS1" DefaultMode="Insert" Font-Names="Arial" Font-Size="10pt" AllowPaging="false" BackColor="white" BorderColor="white" BorderWidth="0px" CellPadding="2" >
<InsertItemTemplate>
<table cellpadding="1" cellspacing="0" border="0">
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#F0F0F0;f
<td style="width:70%;backgroun
<asp:TextBox ID="ParcelIDTextBox" runat="server" style="font-weight:bold;ba
<br /><br />
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%"> &nb
<td style="text-align: left; white-space: nowrap; width: 25%"><span>
<span style="font-weight:normal;
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%" valign="top"><asp:Label ID="Label1" runat="server" Text="Incorrect Current Land Use"></asp:Label> &nb
<td style="text-align: left; white-space: nowrap; width: 25%">
<input type="checkbox" id="chk_ICLU" name="chk_ICLU" onclick="toggle(this,'ther
<!--Incorrect Current Land Use Panel -->
<div id="therow" style="display:none">
<asp:Panel ID="Panel1" runat="server" Visible="true">
<table cellpadding="5" cellspacing="0" border="0" bgcolor="#F0F0F0">
<tr>
<td style="width:30%; text-align:left; vertical-align:top"><asp:L
<td style="width:70%; text-align:left; vertical-align:top">
<asp:DropDownList ID="ddl_ICLU_Correction" runat="server" SelectedValue='<%# Bind("ICLU_Correction") %>' AutoPostBack="false">
<asp:ListItem Value=" " Text="Please Select" Selected="true">Please Select</asp:ListItem>
<asp:ListItem Value="Inconsistent with Imagery" Text="Inconsistent with Imagery">Inconsistent with Imagery</asp:ListItem>
<asp:ListItem Value="Personal Knowledge of Area" Text="Personal Knowledge of Area">Personal Knowledge of Area &nbs
</asp:DropDownList> <
<asp:RequiredFieldValidato
</td>
</tr>
<tr>
<td style="width:30%; text-align:left; vertical-align:top"><asp:L
<td style="width:70%; text-align:left; vertical-align:top">
<asp:DropDownList ID="ddl_ICLU_Specify" runat="server" SelectedValue='<%# Bind("ICLU_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_ICLU" DataTextField="LU_CODE_Des
</asp:DropDownList>
<asp:SqlDataSource id="ds_LU_ICLU" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon
<span style="color:Red">*</span>
<asp:RequiredFieldValidato
</td>
</tr>
</table>
</asp:Panel>
</div>
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%; background-color:#FFFFFF" valign="top"><asp:Label ID="Label2" runat="server" Text="Incorrect Future Land Use"></asp:Label> &nb
<td style="text-align: left; white-space: nowrap; width: 25%">
<input type="checkbox" id="chk_IFLU" name="chk_IFLU" onclick="toggle(this,'ther
<!--Incorrect Future Land Use Panel -->
<div id="therow02" style="display:none">
<asp:Panel ID="Panel2" runat="server">
<table cellpadding="5" cellspacing="0" border="0" bgcolor="#F0F0F0">
<tr>
<td style="width:30%"><asp:Lab
<td style="width:70%">
<asp:DropDownList ID="ddl_IFLU_Specify" runat="server" SelectedValue='<%# Bind("IFLU_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_IFLU" DataTextField="LU_CODE_Des
<asp:SqlDataSource ID="ds_LU_IFLU" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon
<span style="color:Red">*</span>
<asp:RequiredFieldValidato
</td>
</tr>
</table>
</asp:Panel>
</div>
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; width: 30%" valign="top"><asp:Label ID="Label3" runat="server" Text="Future Development At This Location"></asp:Label>&nbs
<td style="text-align: left; white-space: nowrap; width: 25%" valign="top">
<input type="checkbox" id="chk_FDATL" name="chk_FDATL" onclick="toggle(this,'ther
<div id="therow03" style="display:none">
<!--Future Development At This Location Panel -->
<asp:Panel ID="Panel3" runat="server">
<table cellpadding="5" cellspacing="0" border="0" bgcolor="#F0F0F0">
<tr>
<td style="width:30%; text-align:left; vertical-align:top"><asp:L
<td style="width:70%; text-align:left; vertical-align:top">
<asp:DropDownList ID="ddl_FDATL_Specify" runat="server" SelectedValue='<%# Bind("FDATL_Specify") %>' AutoPostBack="false" DataSourceID="ds_LU_FDATL"
</asp:DropDownList>
<asp:SqlDataSource ID="ds_LU_FDATL" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon
SelectCommand="SELECT [LU_CODE_Desc] FROM [RLUIS_LU]"></asp:SqlDataS
<span style="color:Red">*</span>
<asp:RequiredFieldValidato
</td>
</tr>
</table>
<table cellpadding="5" cellspacing="0" border="0" width="100%" bgcolor="#F0F0F0">
<tr>
<td colspan="2" valign="top" align="left" style="width:100%"> </td>
</tr>
<tr>
<td colspan="2" style="width:100%; text-align:left; vertical-align:top">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td style="width:15%; text-align:left; vertical-align:top"><asp:L
<td style="width:85%; text-align:left; vertical-align:top">
<asp:RegularExpressionVali
Display="Dynamic" ErrorMessage="Please limit to 254 characters or less."
ValidationExpression="[\s\
</tr>
</table>
</td>
</tr>
</table><br />
</asp:Panel>
</div>
</td>
</tr>
<!--Name and email textboxes -->
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#FFFFFF "><asp:Label ID="Label7" runat="server" Text="Comments & <br /> Additional Information: "></asp:
<td style="width:70%; text-align:left; vertical-align:top">
<asp:TextBox ID="Comments" runat="server" TextMode="MultiLine" Width="55%" onkeypress="return textboxMultilineMaxNumber(
<asp:RegularExpressionVali
Display="Dynamic" ErrorMessage="Please limit to 254 characters or less."
ValidationExpression="[\s\
</td>
</tr>
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#FFFFFF ">Your Name:<asp:Label ID="Label12" runat="server" AssociatedControlID="Name"
<td style="width:70%; text-align:left; vertical-align:top">
<asp:TextBox ID="Name" Width="55%" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox> <s
<asp:RequiredFieldValidato
</td>
</tr>
<tr>
<td style="width:30%; text-align:right; vertical-align:top; background-color:#FFFFFF "><asp:Label ID="Label13" runat="server" Text="Email:" AssociatedControlID="Email
<td style="width:70%; text-align:left; vertical-align:top">
<asp:TextBox ID="Email" Width="55%" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox> <s
<asp:RequiredFieldValidato
<asp:RegularExpressionVali
ControlToValidate="Email" ValidationExpression="^[a-
</td>
</tr>
<tr>
<td style="width:30%; text-align:left; vertical-align:top; background-color:#ffffff "> </td>
<td style="width:70%; text-align:left; vertical-align:top"><br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Submit"> </asp:Button> &
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:Button>
<br /> <br />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
</td>
</tr>
</table>
<asp:SqlDataSource ID="ds_RLUIS1" runat="server" ConnectionString="<%$ ConnectionStrings:RLUISCon
InsertCommand="INSERT INTO [RLUIS] ([ParcelID], [ICLU_Correction], [ICLU_Specify], [IFLU_Specify], [FDATL_Specify], [FDATL_Source], [Comments], [Name], [Email]) VALUES (@ParcelID, @ICLU_Correction, @ICLU_Specify, @IFLU_Specify, @FDATL_Specify, @FDATL_Source, @Comments, @Name, @Email)"
SelectCommand="SELECT [INPUTID], [ParcelID], [ICLU_Correction], [ICLU_Specify], [IFLU_Specify], [FDATL_Specify], [FDATL_Source], [Comments], [Name], [Email] FROM [RLUIS]"
UpdateCommand="UPDATE [RLUIS] SET [ParcelID] = @ParcelID, [ICLU_Correction] = @ICLU_Correction, [ICLU_Specify] = @ICLU_Specify, [IFLU_Specify] = @IFLU_Specify, [FDATL_Specify] = @FDATL_Specify, [FDATL_Source] = @FDATL_Source, [Comments] = @Comments, [Name] = @Name, [Email] = @Email WHERE [INPUTID] = @INPUTID">
<UpdateParameters>
<asp:Parameter Name="ParcelID" Type="String" />
<asp:Parameter Name="ICLU_Correction" Type="String" />
<asp:Parameter Name="ICLU_Specify" Type="String" />
<asp:Parameter Name="IFLU_Specify" Type="String" />
<asp:Parameter Name="FDATL_Specify" Type="String" />
<asp:Parameter Name="FDATL_Source" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="INPUTID" Type="Int16" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ParcelID" Type="String" />
<asp:Parameter Name="ICLU_Correction" Type="String" />
<asp:Parameter Name="ICLU_Specify" Type="String" />
<asp:Parameter Name="IFLU_Specify" Type="String" />
<asp:Parameter Name="FDATL_Specify" Type="String" />
<asp:Parameter Name="FDATL_Source" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
---------
Thank you.
ASKER
ramkisan,
In my default.aspx.cs file, i have the following code:
-----
protected void SqlDataSource1_Inserted(ob ject sender, SqlDataSourceStatusEventAr gs e)
{
if (e.Exception == null)
{
Response.Redirect("ThankYo u.aspx");
}
}
------
perhaps this is where i insert the code you suggested...
In my default.aspx.cs file, i have the following code:
-----
protected void SqlDataSource1_Inserted(ob
{
if (e.Exception == null)
{
Response.Redirect("ThankYo
}
}
------
perhaps this is where i insert the code you suggested...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ramkisan,
thank you. the code writes a " " to the database if the use does make a selection.
Thank you again.
thank you. the code writes a " " to the database if the use does make a selection.
Thank you again.
<asp:RegularExpressionVali
- And when you clicked the submit button, before insert to database, add the codes below:
if (ddl_ICLU_Specify.Items.Co
{
foreach (ListItem li in ddl_ICLU_Specify.Items)
{
if (li.Value == "Please Select")
{
li.Value = "";
}
}
}