update datagrid with dynamic bound column

D

don

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top