-
July 7th, 2009, 10:39 AM
#1
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>
<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();
}
}
-
July 7th, 2009, 11:35 AM
#2
Re: Message doesn't work:-
You can use a CompareValidator. Take a look here or google some more about CompareValidator
-
July 7th, 2009, 12:46 PM
#3
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
-
July 7th, 2009, 01:18 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|