this is what I am trying to accomplish ... I have a list of events. Each event has tactics on how to implement the event and each tactic has costs.
I am building the tactics list dynamically (can have more than 1 tactic for an event) and trying to build an editable gridview of the costs (can have more than 1 row of costs) for each event. When I click the edit button on the gridview, the fields turn to textboxes but the edit button does not change to update/cancel -- what am I missing???
Thank you!
gview = new System.Web.UI.WebControls.GridView();
gview.ID = "gviewCosts_" + clsEventTactic.Tactics.Tables[0].Rows[I]["TacticID"];
gview.RowEditing += new GridViewEditEventHandler(gviewCosts_RowEditing);
gview.RowUpdating += new GridViewUpdateEventHandler(gviewCosts_RowUpdating);
gview.AutoGenerateColumns = false;
gview.AutoGenerateEditButton = false;
gview.CellSpacing = 1;
gview.CellPadding = 3;
gview.Font.Size = 11;
gview.HeaderStyle.BackColor = System.Drawing.Color.SteelBlue;
gview.HeaderStyle.ForeColor = System.Drawing.Color.White;
intTacticRec = (int)clsEventTactic.Tactics.Tables[0].Rows[I]["RecordID"];
ds = clsEventTactic.GetTacticCostsInfo(intTacticRec);
SetGridViewTemplate(ref gview, ds, "COSTS");
gview.DataSource = ds;
gview.DataBind();
ph.Controls.Add(gview);
++++
private void SetGridViewTemplate(ref GridView _gview, DataSet _ds, string _strWhichGView)
{
TemplateField tf;
ButtonField bf;
_gview.Columns.Clear();
bf = new ButtonField();
bf.ButtonType = ButtonType.Button;
bf.CommandName = "Edit";
bf.Text = "Edit";
bf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
bf.ItemStyle.Width = Unit.Pixel(50);
bf.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
_gview.Columns.Add(bf);
foreach (DataColumn dc in _ds.Tables[0].Columns)
{
tf = new TemplateField();
tf.SortExpression = dc.ColumnName;
tf.HeaderText = dc.ColumnName;
tf.ItemTemplate = new FormattedTemplate(ListItemType.Item, dc);
tf.EditItemTemplate = new FormattedTemplate(ListItemType.EditItem, dc);
dc.ReadOnly = false;
tf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
}
_gview.Columns.Add(tf);
+++++
public class FormattedTemplate : ITemplate, INamingContainer
{
ListItemType _type;
DataColumn _dc;
public FormattedTemplate(ListItemType type, DataColumn dc)
{
_type = type;
_dc = dc;
}
public void InstantiateIn(System.Web.UI.Control container)
{
:<code>
:
txt = new TextBox();
txt.ID = "txt" + _dc.ColumnName;
container.Controls.Add(txt);
txt.MaxLength = 10;
txt.Width = Unit.Pixel(60);
rangeVal = new RangeValidator();
rangeVal.ControlToValidate = txt.ID;
:
}