Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   update datagrid with dynamic bound column (http://www.velocityreviews.com/forums/t761923-update-datagrid-with-dynamic-bound-column.html)

don 04-26-2005 09:21 PM

update datagrid with dynamic bound column
 
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...ridcontrol.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com


All times are GMT. The time now is 07:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.