Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NETC如何生成动态控件_C#_Asp.net_Oracle - Fatal编程技术网

C# ASP.NETC如何生成动态控件

C# ASP.NETC如何生成动态控件,c#,asp.net,oracle,C#,Asp.net,Oracle,我正在使用asp.NETC,我想从数据库生成文本框。我的表中有4条记录,所以在运行时需要4个文本框。 但是当我签入Insepct元素时,我只得到了一个文本框。我得到了4个文本框,但它没有显示在我的页面上 不知道哪里出了问题 我正在使用这样的代码 OracleConnection obj_Conn = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConn"].ToSt

我正在使用asp.NETC,我想从数据库生成文本框。我的表中有4条记录,所以在运行时需要4个文本框。 但是当我签入Insepct元素时,我只得到了一个文本框。我得到了4个文本框,但它没有显示在我的页面上

不知道哪里出了问题

我正在使用这样的代码

OracleConnection obj_Conn = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConn"].ToString());
    Table table = new Table();
    table.ID = "table1";
    string Query = "SELECT * FROM XXCUS.MASTER_VERIFICATION";
    OracleDataAdapter da = new OracleDataAdapter(Query, obj_Conn);
    //DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    da.Fill(dt);
    var Count = dt.Rows.Count;
    if (Count > 0)
    {
        TableRow row = new TableRow();
        TextBox txt = new TextBox();
        for (int i = 0; i < Count; i++)
        {
            TableCell cell = new TableCell();
            txt.ID = "txt" + i.ToString();
            cell.ID = "cell" + i.ToString();

            cell.Controls.Add(txt);

            row.Cells.Add(cell);
        }
        table.Rows.Add(row);
        dvGenerateCntrl.Controls.Add(table);
    }

并在页面加载时调用此方法

将声明新文本框的行放入for循环中


将声明新文本框的行放入for循环中


首先调试代码,确保datatable中有4行并使用此代码

    OracleConnection obj_Conn = new `OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["oracleConn"].ToString());`
    Table table = new Table();
    table.ID = "table1";
    string Query = "SELECT * FROM XXCUS.MASTER_VERIFICATION";
    OracleDataAdapter da = new OracleDataAdapter(Query, obj_Conn);
    //DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    da.Fill(dt);
    var Count = dt.Rows.Count;
    if (Count > 0)
    {
        TableRow row = new TableRow();
        TextBox txt = new TextBox();
        for (int i = 0; i < Count; i++)
        {
TextBox txt = new TextBox();            
TableCell cell = new TableCell();
            txt.ID = "txt" + i.ToString();
            cell.ID = "cell" + i.ToString();

            cell.Controls.Add(txt);

            row.Cells.Add(cell);
        }
        table.Rows.Add(row);
        dvGenerateCntrl.Controls.Add(table);
    }
在代码中,您不会每次都创建TextBox对象。
我认为它会对您有所帮助。

首先调试您的代码,确保您的数据表中有4行并使用此代码

    OracleConnection obj_Conn = new `OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["oracleConn"].ToString());`
    Table table = new Table();
    table.ID = "table1";
    string Query = "SELECT * FROM XXCUS.MASTER_VERIFICATION";
    OracleDataAdapter da = new OracleDataAdapter(Query, obj_Conn);
    //DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    da.Fill(dt);
    var Count = dt.Rows.Count;
    if (Count > 0)
    {
        TableRow row = new TableRow();
        TextBox txt = new TextBox();
        for (int i = 0; i < Count; i++)
        {
TextBox txt = new TextBox();            
TableCell cell = new TableCell();
            txt.ID = "txt" + i.ToString();
            cell.ID = "cell" + i.ToString();

            cell.Controls.Add(txt);

            row.Cells.Add(cell);
        }
        table.Rows.Add(row);
        dvGenerateCntrl.Controls.Add(table);
    }
在代码中,您不会每次都创建TextBox对象。 我想这会对你有帮助