🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.aspdotnet.components.using
Article #259

EditCommandColumn in DataGrid

#259
From: nisbus
Date: Thu, 31 Mar 2005 20:59
64 lines
2622 bytes
Hi,

I've created an .aspx page which dynamically opens tables in a DataGrid.
The problem I'm facing is adding a EditCommandColumn to the grid so I can 
edit the data.

This is how I'm populating the grid:

procedure TWebForm1.PopulateGrid;
var
  sqlcn : SQLConnection;
  sqlda : SqlDataAdapter;
  ds : DataSet;
  dt : DataTable;
  SQL : String;
  connect : String;
  EdtCmdCol : EditCommandColumn;
begin
  Connect := 
'server=***.***.***.***;database='+DrpDwnCountry.SelectedItem.Text+';user 
ID=*******;password=*******';
  SQL := 'SELECT * FROM '+DrpDwnIndustry.SelectedItem.Text;
  sqlcn := SqlConnection.Create(Connect);
  sqlcn.Open;
  try
    Sqlda := SqlDataAdapter.Create(SQL,sqlcn);
    ds := DataSet.Create;
    sqlDa.Fill(ds,'a');
    dt := ds.Tables['a'];
    DataGrid1.DataSource := dt.DefaultView;

  {Here I try to add the column}
    EdtCmdCol := EditCommandColumn.Create;
    EdtCmdCol.EditText := 'Edit';
    EdtCmdCol.CancelText := 'Cancel';
    EdtCmdCol.UpdateText := 'Update';
    EdtCmdCol.ButtonType := ButtonColumnType.PushButton;
    EdtCmdCol.Visible := True;
    DataGrid1.Columns.Add(EdtCmdCol);

    DataBind;
  finally
    sqlcn.Close;
  end;
end;

This results in the first column of the grid being a column with an edit 
button in each row.
When I press the edit button everything in the grid jumps one column to the 
left and the edit buttons disappear.

This is the EditCommand event:

procedure TWebForm1.DataGrid1_EditCommand(source: System.Object; e: 
System.Web.UI.WebControls.DataGridCommandEventArgs);
begin
  DataGrid1.EditItemIndex := e.Item.ItemIndex;
  PopulateGrid;
end;

Can anyone tell me what I'm doing wrong?

thanks,
  nisbus 
Technical Details
Message-ID: <424c64b4@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 21665a,ff3ef9baea9c36ec,start
X-Google-Attributes: gid21665a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "nisbus" <vk@elea.is>
Newsgroups: borland.public.delphi.aspdotnet.components.using
Subject: EditCommandColumn in DataGrid
Date: Thu, 31 Mar 2005 20:59:29 -0000
Lines: 66
Organization: elea
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 194.144.89.139
Message-ID: <424c64b4@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1112302772 194.144.89.139 (31 Mar 2005 12:59:32 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail