Showing posts with label solution. Show all posts
Showing posts with label solution. Show all posts

Monday, March 26, 2012

Passing values to a Series of Dropdown lists on another page...

I know that the simple solution here is a standard page that simple changes a where its looking form the menu, but the higher up that is overseeing the request is die hard agianst the way it looks visually and how it opperates. So what I had to do is create two pages both with a series of 4 dropdownlists that allow selections that get you ultimately to an internal FAQ page.

My question is how can I pass the values of the first page's dropdownlists along to the second page. I created session variable but when I assign the values, I am sure you can guess the error, "Value is not a part of the list..blah, blah, blah". So how can I get the values to match from the previous page's selections?

When you get this error, that means your second page's list doesn't have this value list.

1. Check the session value to make sure your passed value is correct, and is the one in your second page's ddl item list.

2. Add a null ListItem in your second page ddl. catch it to the default selected item if error happens.

Hope it helps


This is exactly what is happening. Is there a way to force the DDL's to complete there SQL which would populate it's lists based on the selection of the previous DDL's value during the Page load event?


Does anyone have any ideas or points in the right direction as to how this can be done. I'm sure it is going to take some extensive coding, but being probably less than a novice and a true "hack" I have no idea where to start.


Gatorzlair:

This is exactly what is happening. Is there a way to force the DDL's to complete there SQL which would populate it's lists based on the selection of the previous DDL's value during the Page load event?

Hi,

Based on my understanding, you want to bind the DropDownLists by the parameters passed from the other page. If I have misunderstood you, please feel free to let me know.

We can bind the DropDownLists by parameters in the Page Load event. First, we need to get the parameters and then get the data source by them to bind the DropDownLists. The following is the simple example:

protected void Page_Load(object sender, EventArgs e) {//Get parameters.string strPara1 = Request.QueryString["Parameter1"];string strPara2 = Request.QueryString["Parameter2"];//Get Data source by the parameters. DataSet ds = GetDataSource(strPara1, strPara2);//Bind DropDownList. DropDownList1.DataSource = ds; DropDownList1.DataTextField ="**"; DropDownList1.DataValueField ="**"; DropDownList1.DataBind(); }

I hope this helps.

Wednesday, March 21, 2012

passing XDocument in DayRenderEvent?

This is probably a very simple solution but I am stumped. I am trying to render events on an asp:calendar control using LINQ. I have code behind that loads up my XDocument during Pageload and calls a dayrender event. But I can't figure out how to get my XDocument into the event argument to be tested on during the "if ..." statements. Here is the code, the commented out section is what is supposed to be run if I could get 'thismonth' into the event handler. The yellow-coloring section was just for testing.

protected void Page_Load(object sender, EventArgs e)
{
XDocument eventsXML = XDocument.Load(Server.MapPath("Events.xml"));

var events = from theeventin eventsXML.Descendants("event")
selectnew
{
Organization = theevent.Element("organization").Value,
Creator = theevent.Element("creator").Value,
Name = theevent.Element("name").Value,
Description = theevent.Element("description").Value,
Location = theevent.Element("location").Value,
EventDate = DateTime.Parse(theevent.Element("Date").Element("Day").Value)
};

var thismonth = from itemin events
where item.EventDate.Month == DateTime.Now.Month
select item;

Calendar1.DayRender +=new DayRenderEventHandler(Calendar1_DayRender);
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend) <-------- Just for testing.
e.Cell.BackColor = System.Drawing.Color.Yellow;

//foreach (var item in thismonth) <------ "thismonth does not exist in this context" how do I get it here?
//{
// if (item.EventDate.Date.Equals(e.Day.Date))
// e.Cell.BackColor = System.Drawing.Color.PaleVioletRed;
//}
}

Still no progress I've given up for now. When I move the entire data-access into the Calendar1_dayrender event it just "Object not an instance" errors out on "select new"

Weldon