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

Recommended Answers

All 7 Replies

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!!!

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

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

if you are working on the same page then viewstate is a handy option..!

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

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.