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
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