Adding a dynamic textbox control to a datagrid with Datatable datasource

Discussion in 'ASP .Net Datagrid Control' started by JC, Sep 30, 2004.

  1. JC

    JC Guest

    Hi,

    I have a datagrid, and I want to bind this to a datatable, and I would
    like to have textbox controls and one button control.

    The problem is the textbox controls - they don't render, at run time
    it just says 'System.Web.UI.WebControls.TableCell'

    Any help would be appreciated.

    TextBox txtQty = new TextBox();
    txtQty.Text="erm";

    TableCell oTc = new TableCell();
    oTc.Controls.Add(txtQty);
    DataTable oDt = new DataTable();
    oDt.Columns.Add("Qty");
    oDt.Columns.Add("Price");
    oDt.Columns.Add("Details");
    oDt.Columns.Add("Action");
    DataRow oDr = oDt.NewRow();
    oDr["Qty"] = oTc;
    oDr["Price"] = "1";
    oDr["Details"] = "1";
    oDt.Rows.Add(oDr);
    dgQty.DataSource = oDt;
    dgQty.DataBind();
    JC, Sep 30, 2004
    #1
    1. Advertising

  2. JC

    Alex Homer Guest

    You seem to be adding the TableCell control to the DataTable, whicvh
    contains the data to be rendered. This is why you see the class name. You
    need to dynamically create the columns in the DataGrid control to include
    the text box. There are plenty of examples on the Web of generating a
    DataGrid dynamically, such as:
    http://www.daveandal.net/books/6744/webforms/dynamicgrid.aspx
    Alex Homer, Sep 30, 2004
    #2
    1. Advertising

  3. JC

    James Crane Guest

    Hi Alex,

    That's a great start for me - much appreciated

    James



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    James Crane, Sep 30, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    494
    S. Justin Gengo
    Jul 16, 2003
  2. J. Babe
    Replies:
    1
    Views:
    8,315
    Kevin Spencer
    Aug 15, 2003
  3. matthew schouppe
    Replies:
    3
    Views:
    2,344
    Scott Allen
    Apr 30, 2004
  4. matthew schouppe

    DataGrid ItemStyle is a textbox and doesn't update the datagrid datasource

    matthew schouppe, Apr 29, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    191
    Scott Allen
    Apr 30, 2004
  5. static DataTable as DataSource for DataGrid

    , Nov 13, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    272
Loading...

Share This Page