【问题标题】:Clear last ROW Cells data when btnDell was clicked单击 btnDell 时清除最后一行单元格数据
【发布时间】:2016-04-22 13:15:43
【问题描述】:

我有一个动态行表(显示/隐藏)。当我点击 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);

这是我在表格中隐藏最后一个可见行的代码。

    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;

【问题讨论】:

    标签: asp.net .net webforms tablerow


    【解决方案1】:

    这个呢?

    ((DateTimeControl)myTbl.Rows.Cast<TableRow>().Last(row => row.Visible).Cells[1].Controls[0]).ClearSelection();
    

    【讨论】:

    • 我现在将尝试判断它是否发生
    【解决方案2】:

    这个怎么样?在你的 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;
                        }
                    }
                }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多