CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    15

    Message doesn't work:-

    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.

    Code:
    <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>


    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();

    }
    }

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Message doesn't work:-

    You can use a CompareValidator. Take a look here or google some more about CompareValidator

  3. #3
    Join Date
    Jun 2009
    Posts
    15

    Re: Message doesn't work:-

    Do you have nay example of dropdown --as it is connected with database
    or is there any other way I can enforce user to select a "TOyr" greater than from yr.

    Thanks

  4. #4
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Message doesn't work:-

    Another (own made) solution is that after you select 'fromYear', refill the 'toYear' dropdown with only values bigger than the toYear. For example, when an user select '2000' as 'fromYear', fill the 'toYear' box with values starting from 2001.

    In this case you don't even have to show any errormessage.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured