【问题标题】:Adding a HTMLButton into a HTMLTableCell in ASP.NET在 ASP.NET 中将 HTMLButton 添加到 HTMLTableCell
【发布时间】:2020-07-30 14:13:26
【问题描述】:

我目前正在 ASP.NET 的帮助下生成动态 HTML 表。 表格的生成效果很好,但我不知道如何将 HTMLButton(将每一行的信息提交给 DB)放入 HTMLTableCell 对象中。

这是来自我的 CodeBehind-File 的简短代码-sn-p:

    for (int i = 0; i < dokuDaten.Count; i++)
        {
            row = new HtmlTableRow(); //Header Row

            cellVorname = new HtmlTableCell();
            cellVorname.InnerText = dokuDaten[i]._VersVorname;
            row.Cells.Add(cellVorname);

            cellNachname = new HtmlTableCell();
            cellNachname.InnerText = dokuDaten[i]._VersNachname;
            row.Cells.Add(cellNachname);

            cellGebDatum = new HtmlTableCell();
            cellGebDatum.InnerText = dokuDaten[i]._VersGeborenAm;
            row.Cells.Add(cellGebDatum);

            cellVersNr = new HtmlTableCell();
            cellVersNr.InnerText = dokuDaten[i]._VersNummer;
            row.Cells.Add(cellVersNr);

            cellBSNR = new HtmlTableCell();
            cellBSNR.InnerText = dokuDaten[i]._BSNR;
            row.Cells.Add(cellBSNR);

            cellLANR = new HtmlTableCell();
            cellLANR.InnerText = dokuDaten[i]._LANR;
            row.Cells.Add(cellLANR);

            cellDM1 = new HtmlTableCell();
            cellDM1.InnerText = dokuDaten[i]._dm1;
            row.Cells.Add(cellDM1);

            cellDM2 = new HtmlTableCell();
            cellDM2.InnerText = dokuDaten[i]._dm2;
            row.Cells.Add(cellDM2);

            cellBRK = new HtmlTableCell();
            cellBRK.InnerText = dokuDaten[i]._brk;
            row.Cells.Add(cellBRK);

            cellKHK = new HtmlTableCell();
            cellKHK.InnerText = dokuDaten[i]._khk;
            row.Cells.Add(cellKHK);

            cellASTM = new HtmlTableCell();
            cellASTM.InnerText = dokuDaten[i]._astm;
            row.Cells.Add(cellASTM);

            cellCOPD = new HtmlTableCell();
            cellCOPD.InnerText = dokuDaten[i]._copd;
            row.Cells.Add(cellCOPD);

            cellVersUnterschriftAm = new HtmlTableCell();
            cellVersUnterschriftAm.InnerText = dokuDaten[i]._VersUnterschriftAm.ToString("dd/MM/yyyy");
            row.Cells.Add(cellVersUnterschriftAm);

            cellArztUnterschriftAm = new HtmlTableCell();
            cellArztUnterschriftAm.InnerText = dokuDaten[i]._ArztUnterschriftAm;
            row.Cells.Add(cellArztUnterschriftAm);

           

            //Button that I want to implement into the cell
            HtmlButton zuordnungsButton = new HtmlButton();
            zuordnungsButton.ID = "btnZuordnung";
            zuordnungsButton.InnerText = "Zuordnen";
            zuordnungsButton.Attributes.Add("Class","btn btn-success");
            zuordnungsButton.ServerClick += SaveButton_Click;


            //The cell where the button should appear in the end
            cellOptionen = new HtmlTableCell();


            tbl.Rows.Add(row);
        }

        TDPlaceHolder.Controls.Add(tbl);

还有我的 aspx 文件:

<div class="form-group-row">
    <asp:PlaceHolder ID="TDPlaceHolder" runat="server"></asp:PlaceHolder>        
</div>   

我的问题是:如何在 ASP.NET 中将 HTMLButton 放入 HTMLTableCell 中? 我真的希望你能帮助我!

【问题讨论】:

  • cellOptionen.Controls.Add(zuordnungsButton); 不工作?也许您稍后会遇到其他一些问题,但这应该可以。
  • 当然,将cellOptionen 添加到行中。
  • 感谢@Homungus 成功了!我对 ASP.NET 很陌生,我认为必须有另一个参数可以将元素添加到单元格中。如果您愿意,可以发布您的答案,以便我接受。 :)

标签: c# html asp.net


【解决方案1】:

试试cellOptionen.Controls.Add(zuordnungsButton);

也许您稍后会遇到一些其他问题,但到目前为止应该可以。

也许可以研究一些数据绑定控件,例如 ListView 等 - 它们比在 asp.net 中动态创建的控件更好处理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    相关资源
    最近更新 更多