tabel og kontroller
Hej!Jeg sidder og roder med tabeller og dynamisk indsættelse af kontroller i tabellen.
Det lykkes også for mig, men den kalder ikke mine events som jeg forventer den gør, nogen som har en ide til hvad der er forkert her.
ASP.net koden
---------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WeekdaysMenu.aspx.cs" Inherits="Menu_WeekdaysMenu" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link href="../styles/main_styles.css" rel="stylesheet" type="text/css" />
<link href="../styles/scroolbars.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
Width="366px" AutoPostBack="True">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" CssClass=".H1" Font-Size="X-Large" Height="34px"
Style="z-index: 100; left: 18px; position: absolute; top: 7px" Width="363px"></asp:Label>
</div>
<asp:Table ID="Table1" runat="server" Height="22px" Style="left: 9px; position: relative;
top: 12px; z-index: 101;" Width="359px">
</asp:Table>
</form>
</body>
</html>
CS Koden
----------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
public partial class Menu_WeekdaysMenu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillDropDown();
FillTable(Menu_Feeder.Instance().GetDay());
this.DropDownList1.SelectedValue = GetDayValue(Menu_Feeder.Instance().GetDay()).ToString();
this.Label1.Text = "Menuen " + Menu_Feeder.Instance().GetDay();
}
else
{
FillTable(Convert.ToString(this.DropDownList1.SelectedItem));
this.Label1.Text = "Menuen " + this.DropDownList1.SelectedItem;
}
}
public void FillDropDown()
{
CultureInfo ci = new CultureInfo("da-DK");
DateTimeFormatInfo dtfi = ci.DateTimeFormat;
this.DropDownList1.Items.Add(new ListItem(dtfi.GetDayName(DayOfWeek.Monday), "0"));
this.DropDownList1.Items.Add(new ListItem(dtfi.GetDayName(DayOfWeek.Tuesday), "1"));
this.DropDownList1.Items.Add(new ListItem(dtfi.GetDayName(DayOfWeek.Wednesday), "2"));
this.DropDownList1.Items.Add(new ListItem(dtfi.GetDayName(DayOfWeek.Thursday), "3"));
this.DropDownList1.Items.Add(new ListItem(dtfi.GetDayName(DayOfWeek.Friday), "4"));
this.DropDownList1.Items.Add(new ListItem(dtfi.GetDayName(DayOfWeek.Saturday), "5"));
this.DropDownList1.Items.Add(new ListItem(dtfi.GetDayName(DayOfWeek.Sunday), "6"));
}
public int GetDayValue(string name)
{
foreach (ListItem li in this.DropDownList1.Items)
{
if (li.Text == name)
return Convert.ToInt32(li.Value);
}
return -1;
}
public void FillTable(string day)
{
Selector.Instance().OpenDatabase();
IDataReader reader = null;
switch (day)
{
case "mandag":
reader = Selector.Instance().Select_MenuCard(DayOfWeek.Monday.ToString());
break;
case "tirsdag":
reader = Selector.Instance().Select_MenuCard(DayOfWeek.Tuesday.ToString());
break;
case "onsdag":
reader = Selector.Instance().Select_MenuCard(DayOfWeek.Wednesday.ToString());
break;
case "torsdag":
reader = Selector.Instance().Select_MenuCard(DayOfWeek.Thursday.ToString());
break;
case "fredag":
reader = Selector.Instance().Select_MenuCard(DayOfWeek.Friday.ToString());
break;
case "lørdag":
reader = Selector.Instance().Select_MenuCard(DayOfWeek.Saturday.ToString());
break;
case "søndag":
reader = Selector.Instance().Select_MenuCard(DayOfWeek.Sunday.ToString());
break;
}
if (reader != null)
{
TranslatorClass tc = new TranslatorClass();
while (reader.Read())
{
TableCell tc_header = new TableCell();
TableRow tr_header = new TableRow();
tc_header.Text = reader["Menu"].ToString();
tr_header.Cells.Add(tc_header);
this.Table1.Rows.Add(tr_header);
TableCell tc_description = new TableCell();
TableRow tr_description = new TableRow();
tc_description.Text = tc.MakeBoldWords(reader["Description"].ToString()) + " for " + reader["Price"].ToString();
tr_description.Cells.Add(tc_description);
this.Table1.Rows.Add(tr_description);
}
TableCell tc_dropdown = new TableCell();
TableRow tr_dropdown = new TableRow();
this.DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
this.DropDownList1.EnableViewState = true;
tc_dropdown.Controls.Add(this.DropDownList1);
tr_dropdown.Cells.Add(tc_dropdown);
this.Table1.Rows.Add(tr_dropdown);
}
Selector.Instance().CloseDatabase();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
FillTable(this.DropDownList1.SelectedItem.Text);
}
}
Jeg forventede at når min dropdownliste i tabellen blev ændret skulle den kalde DropDownList1_SelectedIndexChanged()
Men det gør den ikke