|
I have two pages A and B.
ON page A, I have three drop down boxes ( month , year, and unit_abbr and they have cascading and Auto post backs) and click button to run a report. What I am trying to do is keeping selected drop down list values after the postbacks. The problem right now is when I come back to page A after I browse page B , the selected values in dropdown boxes are set back to the default ( in my case most recent month, year, unit_num). How can I keep the selected values inside of dropdown lists while I am browsing around different pages? If I select month = 1 year 2006 unit_abbr = D11 to run the report on page A, then go to the different page to browse around different report and when I come back to Page A, the selected parameters in those drop down lists should be set to month = 1 year 2006 unit_abbr = D11
Here is my code using session variable:
<asp:label id="Label4" runat="server" text="Select Year:" forecolor="Black" font-bold="True" font-names="Arial" font-size="8pt">
<asp:dropdownlist id="DropDownList2" runat="server" datasourceid="SqlDataSource3" datatextfield="year" datavaluefield="year" font-names="Tahoma" font-size="8pt" autopostback="True" onselectedindexchanged="DropDownList2_SelectedIndexChanged1">
<asp:label id="AccountStatus" runat="server" font-size="16pt" visible="False" width="87px">
<asp:label id="Label5" runat="server" text="Select Month:" forecolor="Black" font-bold="True" font-names="Arial" font-size="8pt">
<asp:dropdownlist id="DropDownList1" runat="server" datasourceid="SqlDataSource2" datatextfield="month" datavaluefield="month" font-names="Tahoma" font-size="8pt" onselectedindexchanged="DropDownList1_SelectedIndexChanged" autopostback="True">
<asp:label id="Label7" runat="server" text="Select Region:" forecolor="Black" font-bold="True" font-names="Arial" font-size="8pt">
<asp:dropdownlist id="DropDownList4" runat="server" autopostback="True" datasourceid="SqlDataSource6" datatextfield="region_name" datavaluefield="Region_num" font-names="Tahoma" font-size="8pt" onselectedindexchanged="DropDownList4_SelectedIndexChanged">
--Here is code behind
public
partial class Dashboard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack && ((this.Session["MMselectedvalue"] != null) && (this.Session["YYselectedvalue"] != null)
if (!Page.IsPostBack && ((this.Session["MMselectedvalue"] != null) && (this.Session["YYselectedvalue"] != null) && (this.Session["Unitselectedvalue"]) != null) && (this.Session["Regionselectedvalue"] != null))
{
this.DropDownList1.SelectedIndex = Convert.ToInt32(this.Session["MMselectedvalue"]);
this.DropDownList2.SelectedIndex = Convert.ToInt32(this.Session["YYselectedvalue"]);
this.DropDownList3.SelectedIndex = Convert.ToInt32(this.Session["Unitselectedvalue"]);
this.DropDownList4.SelectedIndex = Convert.ToInt32(this.Session["Regionselectedvalue"]);
GridView4.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Session["MMselectedvalue"] = this.DropDownList1.SelectedIndex;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
this.Session["YYselectedvalue"] = this.DropDownList2.SelectedIndex;
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
this.Session["Unitselectedvalue"] = this.DropDownList3.SelectedIndex;
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{
this.Session["Regionselectedvalue"] = this.DropDownList4.SelectedIndex;
But, the problem is the data controls of drop downboxe ( sql datasource) are overwriting the session varialbles, so it set back to the default value...
How can I keep the session variables after the data binding ( sql datasource for drop downboxes)? ,and How can I ditermine whether it's just a postback ( changing selected values on the same page) or the user is actually changing the page( navigate different pages and come back to the same page).?
|
|
|
|
|
In the selectedIndexChange event handler add the selected index to a session.
Then in page_load you check for a postback (you do nothing). If there is no postback you check the session if it contains those stored indexes and if it does you fill the drop downs with data and then select the one that is in the session.
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
You may also need to set the selected indexes from session after the ddls are databound.
|
|
|
|
|
How can I do that? Can you provide me some code examples?
|
|
|
|
|
Thanks, I think I almost figured it out.. except the dropdownlist3 is still set back to the default value ( doesn't remember previous selected value). Is it because the dropdownbox3 is populated by the drop down box4 ( cascading dropdown box)? How can I work around this?
--Here is the code for dropdownbox3
<asp:dropdownlist id="DropDownList3" runat="server" datasourceid="SqlDataSource4" datatextfield="unitname_abbr" datavaluefield="unit_abbr" width="352px" font-names="Tahoma" font-size="8pt" onselectedindexchanged="DropDownList3_SelectedIndexChanged" autopostback="True">
<asp:sqldatasource id="SqlDataSource4" runat="server" connectionstring="<%$ ConnectionStrings:Finance_AppsConnectionString %>" selectcommand="
select distinct(unit_name) as unit_name,unit_abbr
, ( convert(varchar(5), unit_abbr) + ' - ' + convert(varchar(50), unit_name))as unitname_abbr
from revenue_aggregate
where region_num = @region_num
group by unit_name, unit_abbr
order by unit_abbr">
<selectparameters>
<asp:controlparameter controlid="DropDownList4" name="region_num" propertyname="SelectedValue">
--------------------------------------------------Updted code
if (!Page.IsPostBack)
{
try
{
this.DropDownList1.SelectedIndex = Convert.ToInt32(this.Session["MMselectedvalue"]);
this.DropDownList2.SelectedIndex = Convert.ToInt32(this.Session["YYselectedvalue"]);
this.DropDownList3.SelectedIndex = Convert.ToInt32(this.Session["Unitselectedvalue"]);
this.DropDownList4.SelectedIndex = Convert.ToInt32(this.Session["Regionselectedvalue"]);
}
catch
{
}
}
else
{
}
|
|
|
|
|
Hi.
I have DataGrid that has 11 columns. Some of the columns are white and some are gray. How can I change row color onmouseover and when put the original color back? I've tried to use in the
ItemDataBound the following
e.Item.Attributes.Add("onmouseover", "changeMouseOverandOut(this, false)")
and in the JavaScript
var lastColorUsed;
function changeMouseOverandOut(row, highlight){
if(!highlight) {
lastColorUsed = row.style.backgroundColor;
row.style.backgroundColor = '#FFFF66';
}
else
row.style.backgroundColor = lastColorUsed;
}
It does work but only for white background. My gray background color doesn't change. Setting background color from ItemDataBound gives the same result so that's why I used JavaScript function (it is nice to try new things).
Please hlep.
|
|
|
|
|
Hi AlexFromTo
Here is a codesample that shows how you can get the desired result for a cell, you can probably modify the code to change a row instead.
http://www.codeproject.com/aspnet/DataGridHelperTool.asp[^]
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
|
am developing a local site
how can i get the ip address of any client once calls any page of the site?
|
|
|
|
|
Request.UserHostAddress()
-
बुरा जो देखण मै चला, बुरा न िमलया कोय,
जो मन खोजा आपणा तो मुझसे बुरा न कोय।
Translation
|
|
|
|
|
thanks for your time
btw great quotation!!!
-- modified at 5:03 Wednesday 3rd May, 2006
|
|
|
|
|
could i find server to upload my files that are aspx
for 2 days or 3 days i mean free? to test my project in internet ?
thank you very much
|
|
|
|
|
could i find server to upload my files that are aspx
for 2 days or 3 days i mean free? to test my project in internet ?
thank you very much
|
|
|
|
|
Hello,
I am creating a web site using ASP.Net using C#. I want customers to buy products from the website. What is the best and most secure way to use different payment methods. The website will need to be able to use credit cards, and another payment method, e.g. paypay. What is the best way to implement these into a ASP.Net website?
Thanks in advance,
Steve
|
|
|
|
|
Nice Information
http://www.programmersheaven.com/2/PayPalIntegration
http://www.devx.com/codemag/Article/29342/1763
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
Hello,
we are using Master Pages in asp.net 2.0. Our Master page has three contentplaceholders. On the left most ContentPlaceHolder we have all the links for the navigation of the site. One of the links on it is "Admin" link. Now, if some one with "Admin" Role logs in and clicks on it then the "Admin" link should populate all the other links underneath the "Admin" link. I am looking for some thing like toggel link.
Can some one please help me how do I accomplish this toggle link type of task.
Thanks
-L
|
|
|
|
|
I have to export reports built in .net 2.0 into pdf, word and xls formats.
Please note that i already have codes for crystal reports but the fact is that these reports are not crystal ones...so i actually have to export the page data in the above mentioned formats..
Please reply soon.. the deadlines are very strict..
Thanks & best regards....
|
|
|
|
|
I am trying to determine if a file is a jpeg
I know I should use the System.Drawing.Imaging.Image class.
And I can see the enumeration to show me what type.
But I can't find a property or method to extract that information.
Please, no answers telling me to check the extension in the file name.
Thanks for helping me.
Thanks,
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
Assuming that this is an uploaded file from the client - can you check the mime type?
|
|
|
|
|
nah. I want to check the file internally. I only want jpeg avatars so I need to make sure the file is a jpeg. I caught one user changing the extension name to fool me.
Thanks tho.
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
You can read the first few bytes of the file and see if it contains a valid JPEG header.
---
b { font-weight: normal; }
|
|
|
|
|
Yeah, I could. But I want the framework to tell me what it is.
I think hacking into the file, while valid, isn't the solution I was looking for.
Thanks for helping tho.
Nick
1 line of code equals many bugs. So don't write any!!
-- modified at 15:57 Tuesday 2nd May, 2006
|
|
|
|
|
If the file can be loaded into a Bitmap object, then you can use this test to see if it is a JPEG/JPG type image:
if( someBitmap.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Jpeg.Guid ) {}
Josh
|
|
|
|
|
Alright cool. I recognize that form from the Image class.
thanks. thats perfect.
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
I have a popup datepicker in my application which is ran using javascript. When I run my application from my pc it works fine but wehen I run my app from a server it causes a problem. The problem is that if I select a date like today 02/05/2006 this will go into the field on my app, when I submit the form in the date goes into the datbase field as 05/02/2006 which is the wrong way round. I am using GMT as the time zone regional setting. The field in the database is datetime.
Anyone any ideas why this is happening?
macca
|
|
|
|