单击 btnDell 时清除最后一行单元格数据
Clear last ROW Cells data when btnDell was clicked
我有一个带有动态行的 table(show/hide)。当我点击 btnDell 时,我最后一个可见的行被隐藏了,但是他们的数据在那里..
这是我第一行的内容:
//Row1 Cells Controls
Label rowNo = new Label();
rowNo.Text = "1-";
TextBox txt11 = new TextBox();
txt11.Height = 19;
TextBox txt12 = new TextBox();
txt12.Height = 19;
TextBox txt13 = new TextBox();
txt13.Height = 19;
DateTimeControl dt11 = new DateTimeControl();
dt11.DateOnly = true;
DateTimeControl dt12 = new DateTimeControl();
dt12.DateOnly = true;
tRow1 = new TableRow();
tRow1.Visible = true;
TableCell tCellZero = new TableCell();
tCellZero.Controls.Add(rowNo);
tRow1.Cells.Add(tCellZero);
TableCell tCellOne = new TableCell();
tCellOne.Controls.Add(txt11);
tRow1.Cells.Add(tCellOne);
TableCell tCellTwo = new TableCell();
tCellTwo.Controls.Add(dt11);
tRow1.Cells.Add(tCellTwo);
TableCell tCellThree = new TableCell();
tCellThree.Controls.Add(dt12);
tRow1.Cells.Add(tCellThree);
TableCell tCellFour = new TableCell();
tCellFour.Controls.Add(txt12);
tRow1.Cells.Add(tCellFour);
TableCell tCellFive = new TableCell();
tCellFive.Controls.Add(txt13);
tRow1.Cells.Add(tCellFive);
myTbl.Rows.Add(tRow1);
这是我在 Table 中隐藏最后一个可见行的代码。
void btnDell_Click(object sender, EventArgs e)
{
if (myTbl.Rows.Cast<TableRow>().Count(row => row.Visible) > 2)
{
myTbl.Rows.Cast<TableRow>().Last(row => row.Visible).Visible = false;
}
}
如何访问单元格 TextBox.Text 和 DateTimeControls.SelectedDate?
myTbl.Rows.Cast<TableRow>().Last(row => row.Visible).Cells[1].Text = string.Empty;
还有这个?
((DateTimeControl)myTbl.Rows.Cast<TableRow>().Last(row => row.Visible).Cells[1].Controls[0]).ClearSelection();
这个怎么样?在您的 If 语句中....
var tableRow = Table1.Rows.Cast<TableRow>().Last(row => row.Visible);
foreach (TableCell item in tableRow.Cells)
{
foreach (Control cntrl in item.Controls)
{
if (cntrl.GetType() == typeof(DateTimeControl))
{
((DateTimeControl)cntrl).ClearSelection();
}
if (cntrl.GetType() == typeof(TextBox))
{
((TextBox)cntrl).Text = string.Empty;
}
}
}
我有一个带有动态行的 table(show/hide)。当我点击 btnDell 时,我最后一个可见的行被隐藏了,但是他们的数据在那里..
这是我第一行的内容:
//Row1 Cells Controls
Label rowNo = new Label();
rowNo.Text = "1-";
TextBox txt11 = new TextBox();
txt11.Height = 19;
TextBox txt12 = new TextBox();
txt12.Height = 19;
TextBox txt13 = new TextBox();
txt13.Height = 19;
DateTimeControl dt11 = new DateTimeControl();
dt11.DateOnly = true;
DateTimeControl dt12 = new DateTimeControl();
dt12.DateOnly = true;
tRow1 = new TableRow();
tRow1.Visible = true;
TableCell tCellZero = new TableCell();
tCellZero.Controls.Add(rowNo);
tRow1.Cells.Add(tCellZero);
TableCell tCellOne = new TableCell();
tCellOne.Controls.Add(txt11);
tRow1.Cells.Add(tCellOne);
TableCell tCellTwo = new TableCell();
tCellTwo.Controls.Add(dt11);
tRow1.Cells.Add(tCellTwo);
TableCell tCellThree = new TableCell();
tCellThree.Controls.Add(dt12);
tRow1.Cells.Add(tCellThree);
TableCell tCellFour = new TableCell();
tCellFour.Controls.Add(txt12);
tRow1.Cells.Add(tCellFour);
TableCell tCellFive = new TableCell();
tCellFive.Controls.Add(txt13);
tRow1.Cells.Add(tCellFive);
myTbl.Rows.Add(tRow1);
这是我在 Table 中隐藏最后一个可见行的代码。
void btnDell_Click(object sender, EventArgs e)
{
if (myTbl.Rows.Cast<TableRow>().Count(row => row.Visible) > 2)
{
myTbl.Rows.Cast<TableRow>().Last(row => row.Visible).Visible = false;
}
}
如何访问单元格 TextBox.Text 和 DateTimeControls.SelectedDate?
myTbl.Rows.Cast<TableRow>().Last(row => row.Visible).Cells[1].Text = string.Empty;
还有这个?
((DateTimeControl)myTbl.Rows.Cast<TableRow>().Last(row => row.Visible).Cells[1].Controls[0]).ClearSelection();
这个怎么样?在您的 If 语句中....
var tableRow = Table1.Rows.Cast<TableRow>().Last(row => row.Visible);
foreach (TableCell item in tableRow.Cells)
{
foreach (Control cntrl in item.Controls)
{
if (cntrl.GetType() == typeof(DateTimeControl))
{
((DateTimeControl)cntrl).ClearSelection();
}
if (cntrl.GetType() == typeof(TextBox))
{
((TextBox)cntrl).Text = string.Empty;
}
}
}