Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2012, 10:55 PM   PM User | #1
Anne Huberman
New to the CF scene

 
Join Date: Feb 2012
Location: California
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Anne Huberman is an unknown quantity at this point
Question Problem setting which item is selected in a DropDownList when the page is loaded

Hi,

I'm using ReportViewer with asp.net 4.0 to display reports on the web. I have a DropDownList on a page that I'm using to redirect to other pages, so I need to have AutoPostBack for the DropDownList set to true so that the SelectedIndexChanged function is called.

I also want to set the initial selected item in the DropDownList when the page is first loaded (or returned to from other pages). I've tried putting this into Page_Load and only doing it when Page.IsPostBack == false, but it's still writing over the user's choice when the user selects something.

Thanks!
Anne Huberman is offline   Reply With Quote
Old 02-02-2012, 08:33 AM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
what does your
Quote:
Page.IsPostBack == false
statement look like? I am guessing by the code you are doing VB and not C#
if VB should look something like this
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
dropdownlist1.SelectedIndex = 0
end If
end Sub
if C# should look like
Code:
protected void Page_Load(object sender, EventArgs e){
  if(!IsPostBack){
  dropdownlist1.SelectedIndex = 0;
  }
}
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 02-07-2012, 06:36 PM   PM User | #3
Anne Huberman
New to the CF scene

 
Join Date: Feb 2012
Location: California
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Anne Huberman is an unknown quantity at this point
Smile

I'm coding in C#. The code is

protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
ddlGroupBy.Items[0].Selected = true;
ddlGroupBy.Items[1].Selected = false;
ddlGroupBy.Items[2].Selected = false;
}
}


I have since found another way around this problem: instead of having 3 aspx pages to go to 3 reportviewers that all take the same data inputs, I set the reportviewer's LocalReport.ReportPath to whichever reportviewer I want.

The odd thing about this is: when I went back to using 3 aspx pages to match my orignial question, I no longer had the problem where Load was getting called with IsPostBack = false when it was overwriting the user's choice! Thanks for your help!
Anne Huberman is offline   Reply With Quote
Reply

Bookmarks

Tags
dropdownlist, selected

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:56 PM.


Advertisement
Log in to turn off these ads.