【发布时间】:2015-12-06 09:41:59
【问题描述】:
在我的网页中,我有日历、表格和按钮。
选择日期后,会触发表格的databind()方法。有 autopostback = true 的复选框。一旦选中,表格就会消失。我不知道在回发后如何使用选中的复选框保留表格。
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.Get("Id") != null)
{
if (!IsPostBack)
{
Calendar1.Visible = false;
}
}
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = Calendar1.SelectedDate.ToShortDateString();
//Set datasource = (cal.selectedDate), the invoking override
// DataBind() method to create table
}
Calendar1.Visible = false;
}
我尝试再次对表格进行数据绑定(IsPostBack),但我无法实现我的目标,相反,它在现有表格的顶部创建了另一个表格
这是用复选框创建表格的方法
public override void DataBind()
{
TableRow myTableRow = default(TableRow);
TableCell myTableCell = default(TableCell);
if (source != null && !(mDate == DateTime.MinValue))
{
for (int i = 0; i <= 23; i++)
{
foreach (DataRow row in source.Tables["Object"].Rows)
{
myTableCell = new TableCell();
CheckBox cb = new CheckBox();
cb.AutoPostBack = true;
cb.Attributes.Add("id", row["objid"].ToString());
cb.InputAttributes.Add("rowID", mDate.Date.AddHours(i).ToString());
myTableCell.Controls.Add(cb);
myTableCell.HorizontalAlign = HorizontalAlign.Center;
myTableRow.Cells.Add(myTableCell);
TimeSheetTable.Rows.Add(myTableRow);
}
}
}
else
{
throw new ArgumentException(" Invalid Date.");
}
}
【问题讨论】:
-
创建表的代码在哪里?这里没有任何东西与表格有关,表格里面是复选框吗?