0

Hi Friends,
I am use asp.net with C#.net as code behind file...
I put asp Dropdown list box to my aspx page..
when at run i select item from Dropdown list box and refresh or post back this aspx.the value of Dropdown become first...How i get previous value...I want dropdown list box value as the static value..want i use session ?? how i solve this problem...
Thank Friends...... Help me :D

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by reach_yousuf
0

Hi Friends,
I am use asp.net with C#.net as code behind file...
I put asp Dropdown list box to my aspx page..
when at run i select item from Dropdown list box and refresh or post back this aspx.the value of Dropdown become first...How i get previous value...I want dropdown list box value as the static value..want i use session ?? how i solve this problem...
Thank Friends...... Help me :D

1) On ddl Selectedindexchanged event save the session value

Private Sub myddl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JobRankID.SelectedIndexChanged
session("myvalue") = myddl.selectedvalue
end sub

2) on page load event retrieve back the selected value from session

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
if not isnothing(session("myvalue")) then
myddl.selectedvalue = session("myvalue")

end if
end sub

Mark as solved if it helps you!!!

Edited by reach_yousuf: n/a

0

PS:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
        <asp:ListItem>A</asp:ListItem>
        <asp:ListItem>B</asp:ListItem>
        <asp:ListItem>C</asp:ListItem>
    </asp:DropDownList>
    &nbsp;&nbsp;
    <a href ="test.aspx">Refresh</a>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("test.aspx");
    }

when i click hyper link or Button1..the value of DropDownList1 become default
Please hepl ME

0

thanks reach_yousuf for ur help
is there any solution except using session ?

0

Friend dnanetwork,
How i use viewstate.. could u give me an example please

0

friend reach_yousuf,
This code is not solution...
because At the first value,what i was select,This code is working what i expected...
but second time,what i was select some value form dropdown List,this code is not working correctly..because first execute page_load() event and secondly execute dropdown SelectedIndexChanged() There for It is not working correctly...
What am i do .... Please help me .... Thank for all who help me

0

friend reach_yousuf,
This code is not solution...
because At the first value,what i was select,This code is working what i expected...
but second time,what i was select some value form dropdown List,this code is not working correctly..because first execute page_load() event and secondly execute dropdown SelectedIndexChanged() There for It is not working correctly...
What am i do .... Please help me .... Thank for all who help me

It should be simple,in Page_load event, wrap your code inside ispostback.

if not ispostback then
'//bind your session value to ddl
end if

Edited by reach_yousuf: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.