My problem is so flexible, so I dont know what is the right title for this question. I'll try to describe my problem clearly, hope you can understand, if you dont, please ask.
I use a DropDownList in my notice.aspx page.
DropDownlist value: 1--> show notice in one day ago; 2--> 7 days ago;3--> 30 days ago.
<asp:DropDownList ID="DropDownListTime" runat="server" OnSelectedIndexChanged="IndexNotice_Changed"
AutoPostBack="true" >
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem Value="1"> 1 day ago </asp:ListItem>
<asp:ListItem Value="2"> 7 days ago </asp:ListItem>
<asp:ListItem Value="3"> 30 days ago </asp:ListItem>
</asp:DropDownList>
And code in notice.aspx.cs
private static string key;
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
BindData();
}
}
public void BindData()
{
string sql="";
if (string.IsNullOrEmpty(DropDownListTime.SelectedValue))
{
key = "3";
}
else
{
key = DropDownListTime.SelectedValue.ToString();
}
if(key.Equals("1"))
{
sql="select top 5 notice in 1 day ago...";//show
}
if(key.Equals("2"))
{
sql="select top 5 notice in 7 day ago...";
}
if(key.Equals("3"))
{
sql="select top 5 notice in 30 day ago...";
}
Datatable dt= excute(sql);
...
HyperLink1.NavigateUrl = string.Format("Allnotice.aspx?key={0}",key);// go to page to show all notices with `1 day`,`7days`,`30 days` ago depend on the `key`
}
public void IndexNotice_Changed(Object sender, EventArgs e)
{
BindData();
}
When I click on the Hyperlink1, the key alway is 3; so the Allnotice.aspx page is alway show the notices in 30days ago.
I really dont know why the value of dropdownlist is always 3. Is there any mistake in my code above, please help!!!
UPDATE:
I've deleted the line: private static string key;
and declare string key=""
in BindData()
it still works wrong.
It seems there is no problem with DropDownListTime.SelectedValue
. When I debug, I saw the variable key is right (I mean it is right with the time I choosed). But when I click on the Hyperlink, the addressbar is show the key=3
.
Help!!!