C# 单击表格单元格时,动态创建的Asp表格将不可见
我正在处理一个项目,因为我有一个用于选择类的下拉列表。然后,对于所选类,将显示其时间表。我使用asp表格动态创建了此时间表,并在表格单元格上添加了单击事件。但是,当我单击表格单元格时,整个表格将不可见。我以前使用asp表格执行相同类型的操作东西,当时我也遇到了同样的错误,但当我在页面加载事件中将create table方法放在post back方法之外时,它得到了解决。但在这里,我在下拉选择的索引更改时调用了create time table方法。我尝试将asp表放在更新面板中,但这也没有解决我的问题 下面是我的aspx代码C# 单击表格单元格时,动态创建的Asp表格将不可见,c#,asp.net,sql,C#,Asp.net,Sql,我正在处理一个项目,因为我有一个用于选择类的下拉列表。然后,对于所选类,将显示其时间表。我使用asp表格动态创建了此时间表,并在表格单元格上添加了单击事件。但是,当我单击表格单元格时,整个表格将不可见。我以前使用asp表格执行相同类型的操作东西,当时我也遇到了同样的错误,但当我在页面加载事件中将create table方法放在post back方法之外时,它得到了解决。但在这里,我在下拉选择的索引更改时调用了create time table方法。我尝试将asp表放在更新面板中,但这也没有解决我
<asp:Panel ID="pnltimetable" runat="server" Visible="false">
<asp:Table ID="tbltimetable" CssClass="timetable" runat="server" CellSpacing="25" GridLines="Both"></asp:Table>
</asp:Panel>
下面是我的cs代码
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserType"] == null)
{
Response.Redirect("Login.aspx");
}
if (!IsPostBack)
{
filldrpclass();
}
}
//method for making timetable
protected void makeTimetable()
{
string periodno = "";
//getting all periods
sql = "SELECT * FROM tblperiodtime order by periodnumber";
ds = obj.openDataset(sql, Session["schoolcode"].ToString());
//getting timetable of the selected class
sql = "SELECT t.*,s.subjectname,tc.teachername FROM tbltimetable t join tblsubject s on s.sshortname=t.subject join tblteacher tc on tc.tshortname=t.tchrshortnm where t.classcode='" + drpclass.SelectedItem.Value + "' order by t.period";
DataSet dsTimetbl = new DataSet();
dsTimetbl = obj.openDataset(sql, Session["schoolcode"].ToString());
DataRow[] drtimetbl;
//To clear previously added rows
tbltimetable.Rows.Clear();
//some entries exists for periods
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count + 1; i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < 7; j++)
{
TableCell tc = new TableCell();
if (i == 0)
{
tc.CssClass = "periodTableCelldays";
tc.HorizontalAlign = HorizontalAlign.Center;
if (j == 0)
tc.Text = "Periods";
else
{
//get week day name from integer value
string weekday = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[j];
//for displaying text in the form of Weekday eg MON
tc.Text = (weekday.Substring(0, 3)).ToUpper();
}
tr.Cells.Add(tc);
tbltimetable.Rows.Add(tr);
}
else
{
tc.HorizontalAlign = HorizontalAlign.Center;
if (j == 0)
{
//showing period number and timing
tc.CssClass = "periodtime";
tc.Text = "0" + ds.Tables[0].Rows[i - 1]["periodnumber"].ToString() + "<br/>" + ds.Tables[0].Rows[i - 1]["starttime"].ToString() + "-" + ds.Tables[0].Rows[i - 1]["stoptime"].ToString();
periodno = "0" + ds.Tables[0].Rows[i - 1]["periodnumber"].ToString();
tr.Cells.Add(tc);
}
else
{
//selecting particular period
drtimetbl = dsTimetbl.Tables[0].Select("period='" + periodno + "' and weekday='" + j + "'");
clickablecell ctCell = new clickablecell();
ctCell.HorizontalAlign = HorizontalAlign.Center;
if (drtimetbl.Length != 0)
{
ctCell.CssClass = "viewlessonplan";
Random rnd = new Random();
ctCell.ID = j + "-" + periodno + "-" + ds.Tables[0].Rows[i - 1]["starttime"].ToString() + "-" + ds.Tables[0].Rows[i - 1]["stoptime"].ToString() + "-" + "Edit-" + drtimetbl[0]["id"].ToString() + "-" + "Subject-" + drtimetbl[0]["subjectname"].ToString() + "-" + "Teacher-" + drtimetbl[0]["teachername"].ToString();
//ctCell.ID = drtimetbl[0]["id"].ToString() + "-" + (i * j + i + j).ToString();
ctCell.Text = drtimetbl[0]["subjectname"].ToString() + "<br/> by<br/>" + drtimetbl[0]["teachername"].ToString() + "<br/>Edit Period";
ctCell.Attributes.Add("onmouseover", "defColor=this.style.backgroundColor; this.style.backgroundColor='LightGray';");
ctCell.Attributes.Add("onmouseout", "this.style.backgroundColor=defColor;");
ctCell.Click += new clickablecell.ClickEventHandler(textcell_Click);
}
else
{
ctCell.Text = "Create Period";
//weekday-period-starttime-stoptime
ctCell.ID = j + "-" + periodno + "-" + ds.Tables[0].Rows[i - 1]["starttime"].ToString() + "-" + ds.Tables[0].Rows[i - 1]["stoptime"].ToString()+"-Create-0-Subject-null-Teacher-null";
ctCell.CssClass = "noperiod";
}
tr.Cells.Add(ctCell);
}
tbltimetable.Rows.Add(tr);
}
}
}
tbltimetable.Visible = true;
pnltimetable.Visible = true;
}
//if no entries exists for periods
else
{
tbltimetable.Visible = false;
pnltimetable.Visible = false;
lblalerts.Text = "Time Table/Lesson Plan not created yet";
lblalerts.Visible = true;
divalerts.Visible = true;
}
}
//table cell's click event
void textcell_Click(object sender, EventArgs e)
{
makeTimetable();
clickablecell _ctcell = (clickablecell)sender;
string weekday = (_ctcell.ID.Split('-')[0]).ToString();
string period = (_ctcell.ID.Split('-')[1]).ToString();
string starttime = (_ctcell.ID.Split('-')[2]).ToString();
string stoptime = (_ctcell.ID.Split('-')[3]).ToString();
string operationtype = (_ctcell.ID.Split('-')[4]).ToString();
string timetableid = (_ctcell.ID.Split('-')[5]).ToString();
string subjectname = (_ctcell.ID.Split('-')[7]).ToString();
string teachername = (_ctcell.ID.Split('-')[9]).ToString();
if (operationtype == "Edit")
{
lbledit_heading.Text = "Edit Period";
//for preselecting subjects when edit period is selected
foreach (ListItem li in drpSubjects.Items)
{
if (li.Text == subjectname)
li.Selected = true;
}
//for preselecting days
foreach (ListItem li in drpDays.Items)
{
if (li.Value == weekday)
li.Selected = true;
}
//for preselecting teachers
foreach (ListItem li in drpteachers.Items)
{
if (li.Text == teachername)
li.Selected = true;
}
}
else
lbledit_heading.Text = "Create Period";
//filling controls in popup
filldrpsubjects();
filldrpteachers();
lnkHidden_ModalPopupExtender.Show();
}
受保护的无效页面加载(对象发送方,事件参数e)
{
if(会话[“用户类型”]==null)
{
重定向(“Login.aspx”);
}
如果(!IsPostBack)
{
filldrpclass();
}
}
//制定时间表的方法
受保护的无效时间表()
{
字符串周期号=”;
//获取所有周期
sql=“按时段编号从tblperiodtime顺序中选择*”;
ds=obj.openDataset(sql,会话[“学校代码”].ToString());
//获取所选课程的时间表
sql=“从tbltimetable中选择t.*,s.subjectname,tc.teachername在s.sshortname=t上加入tblsubject,在tc.tshortname=t.tchrshortnm上加入TBLTacher tc,其中t.classcode=”“+drpclass.SelectedItem.Value+“'order by t.period”;
数据集DSTIMEBL=新数据集();
dsTimetbl=obj.openDataset(sql,会话[“学校代码”].ToString());
DataRow[]drtimetbl;
//清除以前添加的行的步骤
tbltimetable.Rows.Clear();
//某些条目存在于期间
if(ds.Tables[0].Rows.Count!=0)
{
对于(int i=0;i”+drtimetbl[0][“teachername”]。ToString()+“
编辑期间”;
添加(“onmouseover”,“defColor=this.style.backgroundColor;this.style.backgroundColor='LightGray';”;
ctCell.Attributes.Add(“onmouseout”,“this.style.backgroundColor=defColor;”);
ctCell.Click+=新建clickablecell.ClickEventHandler(textcell\u Click);
}
其他的
{
ctCell.Text=“创建期间”;
//工作日期间开始时间停止时间
ctCell.ID=j+“-”+periodno+“-”+ds.Tables[0]。行[i-1][“starttime”]。ToString()+“-”+ds.Tables[0]。行[i-1][“stoptime”]。ToString()+“-创建-0-Subject-null-Teacher-null”;
ctCell.CssClass=“noperiod”;
}
tr.Cells.Add(ctCell);
}
tbltimetable.Rows.Add(tr);
}
}
}
tbltimetable.Visible=true;
pnltimetable.Visible=true;
}
//如果期间不存在任何条目
其他的
{
tbltimetable.Visible=false;
pnltimetable.Visible=false;
lblalerts.Text=“未创建时间表/课程计划
Visible="false"
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserType"] == null)
{
Response.Redirect("Login.aspx");
}
if (!IsPostBack)
{
filldrpclass();
pnltimetable.Visible = false; //initially hidden
}
}