update datagrid with dynamic bound column

Discussion in 'ASP .Net Datagrid Control' started by don, Apr 26, 2005.

  1. don

    don Guest

    I have a simple question which is how to get the entered values on update so I can save them to a database? Specifically I call findControl to get the textbox but the control can't be found. I populate the grid and handle update as shown below.

    protected void BindData()
    {
    DataSet ds = projectHandler.GetProjectList();
    dg.DataSource = ds;
    foreach(DataColumn c in ds.Tables[0].Columns)
    {
    dg.Columns.Add(CreateDataGridColumn(c));
    }
    dg.DataBind(); }

    protected BoundColumn CreateDataGridColumn(DataColumn c)
    {
    BoundColumn column = new BoundColumn();
    column.DataField = c.ColumnName;
    column.HeaderText = c.ColumnName;
    return column;
    }

    private void dg_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    TextBox tb = (TextBox) e.Item.FindControl("Client");
    Debug.WriteLine("Edit Command Args = " + e.CommandArgument);
    Debug.WriteLine("Edit Command Name = " + e.CommandName);
    Debug.WriteLine("Edit Command Source = " + e.CommandSource);
    Debug.WriteLine("Item ID = " + e.Item.ID);
    Debug.WriteLine("Controls Count = " + e.Item.Controls.Count);
    Debug.WriteLine("Cells Count = " + e.Item.Cells.Count);
    Debug.WriteLine("Data Item = " + e.Item.DataItem);
    Debug.WriteLine("Textbox = " + tb);

    dg.EditItemIndex = -1;
    BindData();
    }


    UpdateCommand debug output:

    Edit Command Args =
    Edit Command Name = Update
    Edit Command Source = System.Web.UI.WebControls.DataGridLinkButton
    Item ID =
    Controls Count = 1
    Cells Count = 1
    Data Item =
    Textbox =

    From http://www.developmentnow.com/g/12_0_0_0_0_0/dotnet-framework-aspnet-datagridcontrol.htm

    Posted via DevelopmentNow.com Groups
    http://www.developmentnow.com
     
    don, Apr 26, 2005
    #1
    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. John E.
    Replies:
    3
    Views:
    4,508
    masoud bayan
    Mar 25, 2005
  2. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,355
    thushara wijeratna
    Oct 7, 2008
  3. Ravichandran Mahalingam

    Bound Column or Template Column (w dAdapater?) in DataGrid

    Ravichandran Mahalingam, Jan 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    249
    Ravichandran Mahalingam
    Jan 9, 2004
  4. John E.

    Move bound column to right of dynamic column in datagrid?

    John E., Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    256
    Elton Wang
    Mar 28, 2005
  5. TS
    Replies:
    3
    Views:
    424
    Walter Wang [MSFT]
    Aug 16, 2007
Loading...

Share This Page