I need to show a message as a label whenever user selecct To year less than from year.
I have created a label "lblYrChk" --doesn't work .
what i am doing wrong.
Pl. help.

<asp:ObjectDataSource ID="Srcfmyr" runat="server" 
                 OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
                 TypeName="HITS.App_code.stateTableAdapters.SOURCE_YEAR_VWTableAdapter">                 
                 <SelectParameters>
                     <asp:ControlParameter ControlID="RBl1" Name="myType" 
                         PropertyName="SelectedValue" Type="String" DefaultValue="G" />
             </SelectParameters>
             </asp:ObjectDataSource>
           From: <asp:DropDownList ID="ddlyr" runat="server"
                     OnSelectedIndexChanged="ddlyr_SelectedIndexChanged"    
                AutoPostBack="True" DataSourceID="Srcfmyr" 
                DataTextField="SOURCE_YEAR"              
                DataValueField="SOURCE_YEAR"  Font-Underline="False" >
            </asp:DropDownList>&nbsp; &nbsp; &nbsp; 
              
          <asp:ObjectDataSource ID="SrcToyr" runat="server" 
                 OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
                 TypeName="HITS.App_code.stateTableAdapters.SOURCE_YEAR_VWTableAdapter">
                 <SelectParameters>
                     <asp:ControlParameter ControlID="RBl1"
                      DefaultValue="G" Name="myType" 
                         PropertyName="SelectedValue" 
                         Type="String" />
                 </SelectParameters>
            </asp:ObjectDataSource>
             <asp:Label ID="lblTo" runat ="server" Text="To:"></asp:Label>
            <asp:DropDownList ID="ddlTo" runat="server"  
                AutoPostBack="True" DataSourceID="Srcfmyr" 
                DataTextField="SOURCE_YEAR" 
                DataValueField="SOURCE_YEAR"  
                Font-Underline="False"
                 OnSelectedIndexChanged="ddlTo_Clicked" >
            </asp:DropDownList>
            <br />
             <asp:Label ID="lblYrChk" runat="server" Text=" " ForeColor="#993300"></asp:Label>          
         </td>

And in C#

protected void ddlyr_SelectedIndexChanged(object sender, EventArgs e)
{
Int16 fmyr = Convert.ToInt16(ddlyr.SelectedValue);
Int16 toyr = Convert.ToInt16(ddlTo.SelectedValue);
if (fmyr > toyr)
{
lblYrChk.Text = "**Check Years**";
}
else
lblYrChk.Text = "";


sSQL += "AND SOURCE_YEAR ='" + ddlyr.SelectedItem.ToString() + "'";
MakeSQL();


}

protected void ddlTo_Clicked(object sender, EventArgs e)
{
string sSQLfy = "";

string toval = ddlTo.SelectedItem.ToString();
string fmval = ddlyr.SelectedItem.ToString();

if (ddlTo.SelectedIndex != -1)
{
Int16 fmyr = Convert.ToInt16(ddlyr.SelectedValue); 
Int16 toyr = Convert.ToInt16(ddlTo.SelectedValue);
if (toyr > fmyr)
{
lblYrChk.Text = "**Check Years**";
}
else
lblYrChk.Text = "";

sSQLfy = "AND SOURCE_YEAR between '" + toval + "' AND '" + fmval + "'";
sSQL =sSQLfy.ToString();
MakeSQL();

} 
}

try use this dropdown.SelectedItem.Value to retrieve the values from the drop down box.

regards.

i tried but doesn't work
is there any other way i can enforce user to select "To yr" greater than from year.
Pl. help
Thanks

The easiest way to do it is with a compare validator control <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="DropDownList2" ControlToValidate="DropDownList1" Type="Integer" Operator="LessThan" ErrorMessage="DropDownList2 must be greater than DropDownList1" Display="dynamic"></asp:CompareValidator> DropDownList2 is the ToYr and DropDownList1 is FromYr

regards.

This question has already been answered. Start a new discussion instead.