如何从Tablecell ASP.NET检索数据 [英] How to retrieve data from tablecell ASP.NET

查看:68
本文介绍了如何从Tablecell ASP.NET检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我加载页面时,我发送表将具有的行数:

When I load the page I send the number of rows the table will have:

protected void Page_Load(object sender, EventArgs e)
{
    string numFilas = Request.QueryString["filas"];
    tblAdd.Visible = true;
    for (int i = 0; i < int.Parse(numFilas); i++)
    {
        TableRow NewRow1 = new TableRow();
        TableCell NewCell1 = new TableCell();
        TableCell NewCell2 = new TableCell();

        TextBox txtBox1 = new TextBox();
        txtBox1.Width = 200;
        TextBox txtBox2 = new TextBox();
        txtBox2.Width = 200;
        // adding lebel into cell
        NewCell1.Controls.Add(txtBox1);
        NewCell2.Controls.Add(txtBox2);
        // adding cells to row
        NewRow1.Cells.Add(NewCell1);
        NewRow1.Cells.Add(NewCell2);

        tblAdd.Rows.Add(NewRow1);
    }
}

现在,当我单击提交时,我想检索表格中文本框的数据,我能做到的是:

now when I click submit I'd like to retrieve the data of the textbox inside the table, what I've been capable of is this:

  public void submit(Object sender, EventArgs e)
{
    for (Int32 i = 0; i < tblAdd.Rows.Count; i++)
    {
        TableRow dr = tblAdd.Rows[i];
        TableCell hhh = dr.Cells[0];
        String textCell = hhh.Text();

    }
}

但是,单元格中的文本为空,因为用户写的文本在文本框中,我不知道该怎么获得。

However, the text in the cells is empty because the text the user writes is IN the textbox, which I don't know how to get it.

推荐答案

尝试这


  1. 在创建文本框时添加ID

例如

txtBox1.ID = "txtBox1";




  1. 然后您可以轻松找到它来自当前单元格控件集合的TextBox控件如下。

  1. Then you can easily find this TextBox control from the current Cell's Controls collection as follows.

string textCell =((TextBox)dr.Cells [0] .FindControl( txtBox1))。Text;

string textCell = ((TextBox)dr.Cells[0].FindControl("txtBox1")).Text;

希望您能理解我的意思。基本上,您需要在单元格中找到控件。

Hope you understood what I'm trying to say. Basically, you need to find your control in the Cell.

投票并接受答案(如果它解决了您的问题)。

Vote and accept the answer if it solved your issue.

干杯!

这篇关于如何从Tablecell ASP.NET检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆