Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void BtnSubmit_Click(object sender, EventArgs e)
{
Division = DdlDivision.SelectedItem.ToString();
DataTable dt = getInfo.GetDivision(Division, UserName);
}

protected void BtnAdd_Click(object sender, EventArgs e)
{
Division = DdlDivision.SelectedItem.ToString();
Response.Redirect("FormAddition.aspx");
}
Hi Guys, i need help to retain dDl.selectedItem from one page to another

this is the coding in my FormConfirm.aspx, and i am trying to set the same value in the DDlDivision to go to FormAddition.aspx on form load.

1. it should take the FormConfirm.aspx's DDlDivision.selectedItem and retain it when it redirects to FormAddition.aspx
2.when in FormAddition.aspx and user decides to chenge the SelectedItem in the ddlDivision it should be retained when the button to go back to FormConfirm.aspx is clicked.

any sugestions will be highlly appreciated ..Thanks in advance
Posted

You can make use of session variable. Store selected item value in session.
On FormAddition.aspx, you can retrieve that value from session and use it.
Even if user goes back to FormConfirm.aspx, you can again retrieve value from session and point it to your dropdown selection.
 
Share this answer
 
Comments
mampaf 23-Jan-15 1:24am    
thanks but how do i use session? please pardon me i am new to developing and not familier of most thing. i appreciate ur time and help though, thanks
nagendrathecoder 23-Jan-15 2:08am    
You can do something like this:
Session["Varialble_Name"] = Your_selected_value;

On next page while retrieving session:
string selectedValue = Convert.ToString(Session["Variable_Name"]);
I think your best bet would be to put it in Session variable. Though you can use querystring and all but in the long term it may get complicated.
With session, you can keep data as long as the user session is active and you can use it on any page, not just on these two pages.

Though, if this is going to be customer facing high volume site, you should be aware of pros and cons of using it inproc/outproc, impact of app pool recycling etc.

Hope that helps.
 
Share this answer
 
You can be use query string but in query string value would be show and another yo can be use session variable.

Query String:-

Response.Redirect("FormAddition.aspx?id="Division);

And On Addition Page

You can get value on page load

string str=Request.QueryString("id").ToString();

Session:

Session["str"]=Division;
 
Share this answer
 
Comments
mampaf 23-Jan-15 1:15am    
i tried the query.string one but it gives me an error "An exception of type 'System.NullReferenceException' occurred in App_Web_tro2fhnx.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object." and since i am new to developing i have no idea what it wants me to do
ekanshsaxena 23-Jan-15 5:01am    
if you can be use query string than Division should be pass in this code must

Response.Redirect("FormAddition.aspx?id="Division);

if you do not pass division value than system give error of null exception.

otherwise you can be use Session["value"]=Division;

And Other Page string value=Session["value"].tostring();
Help yourself to
1. MSDN[^].
2. Transferring page values to another page[^]
 
Share this answer
 
v2
Comments
mampaf 23-Jan-15 1:48am    
i tried this on my addition page
protected void Page_Load(object sender, EventArgs e)
{
txtSalRef.Focus();

Division = (string)(Session["Division"]);
if (!Page.IsPostBack)
{
UpdatedBy = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name.Substring(12);
LoadDropDown();
}
}

and on confirmation page i have this but still does not work

if (Page.IsPostBack==false)
{
Name = getInfo.GetUserDetails(UserName);
DataSet ds = getInfo.FillDropDownList(Division, UserName);

DdlDivision.DataSource = ds;
DdlDivision.DataValueField = "Division";
DdlDivision.DataTextField = "Division";
DdlDivision.DataBind();

DataTable plandetails = getInfo.getSurveyNomineeList(UserName);
GridView2.DataSource = plandetails;
GridView2.DataBind();
GridView2.Sort("Name", SortDirection.Ascending);
GridView2.Visible = true;
Division = DdlDivision.SelectedItem.ToString();
Session["Division"] = Division;

if (DdlDivision.SelectedItem.ToString() != null)
{
DataTable dt = getInfo.GetDivision(Division, UserName);
GridView2.DataSource = dt;
GridView2.DataBind();
GridView2.Sort("Name", SortDirection.Ascending);
Division = DdlDivision.SelectedItem.ToString();
}
}
Thanks for your time and responds guy, i got the solution ...

On FormAddition

Pageload ()
{
Division = Request.QueryString["Div"]; // gets Division from FormConfirmation
LoadDropDown()
}
private void LoadDropDown()
{
DdlDivision.SelectedValue = Division;// sets the default DdlDivision value to what we get from FormConfirmation
}

on FormConfirmation

protected void BtnAdd_Click(object sender, EventArgs e)
{
Division = DdlDivision.SelectedItem.ToString();
Response.Redirect("FormAddition.aspx?Div=" + Division);
}

then repeat the same coding on the other Page (mine is FormConfirmation) but replacing "Division and Div" with different variable names to avoid causing ambiguity I used "Location and Loc" and the coding goes like :

FormConfirmation Pageload ()
{
Location = Request.QueryString["Loc"]; // gets Location from FormAddition
LoadDropDown()
}
private void LoadDropDown()
{
DdlDivision.SelectedValue = Location;// sets the default DdlDivision value to what we get from FormAddition
}

on FormAddition

protected void BtnConfirm_Click(object sender, EventArgs e)
{
Location = DdlDivision.SelectedItem.ToString();
Response.Redirect("FormAddition.aspx?Loc=" + Locationn);
}

and it works in a morvelous way :-) thanks guys Enjoy and have FUN Coding
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900