hi

I am Creating Datgrid Programmatically. looking at the code provided in
[url]http://www.dotnetbips.com/displayarticle.aspx?id=66[/url]

The example Adds Button Column after the DataBound Column
i am able to get the values of the Datagrid using the following code
in SelectedIndexChange

dgrid.SelectedItem.Cells[0].Text

My problem is if I add the Select and Edit Button Coulmn before the DataBound Column

i am unable to get the datagrid column values



Thanks
huzaifa

Here is my code

dgrid=new DataGrid();

dgrid.BorderWidth=Unit.Pixel(2);

dgrid.CellPadding=2;

dgrid.GridLines=GridLines.Both;

dgrid.BorderColor=Color.Blue;

dgrid.ShowHeader=true;

dgrid.ShowFooter=true;

dgrid.AutoGenerateColumns=false;

dgrid.SelectedItemStyle.BackColor=Color.Yellow;

dgrid.DataKeyField=sDataKeyField;

dgrid.AllowPaging =true;


dgrid.PagerStyle.Mode = PagerMode.NumericPages;

dgrid.HeaderStyle.Font.Bold=true;

dgrid.HeaderStyle.Font.Name="Verdana";

dgrid.HeaderStyle.Font.Size=FontUnit.Point(10);

dgrid.HeaderStyle.HorizontalAlign=HorizontalAlign. Center;

dgrid.Width=Unit.Percentage(dGridWidth);

if(iPageSize!=0)

{

dgrid.PageSize=iPageSize;

}

else

{

dgrid.PageSize=10;

}

dgrid.BorderColor=Color.Chocolate;

dgrid.BorderWidth=Unit.Pixel(2);

BoundColumn dgridcol;

ButtonColumn btncol;

btncol=new ButtonColumn();

btncol.ButtonType=ButtonColumnType.LinkButton;

btncol.Text="Select";

btncol.CommandName="Select";

dgrid.Columns.Add(btncol);

btncol.Visible=true;

BoundColumn dgridcol=new BoundColumn();

dgridcol.HeaderText="Name";

dgridcol.DataField="name";

dgrid.Columns.Add(dgridcol);

dgridcol=new BoundColumn();

dgridcol.HeaderText="User Id";

dgridcol.DataField="userid";

dgridcol.Visible=false;

dgrid.Columns.Add(dgridcol);

dgridcol=new BoundColumn();

dgridcol.HeaderText="User Name";

dgridcol.DataField="username";

dgrid.Columns.Add(dgridcol);

dgridcol=new BoundColumn();

dgridcol.HeaderText="IsActive";

dgridcol.DataField="isactive";

dgrid.Columns.Add(dgridcol);

dgrid.ItemCreated +=new System.Web.UI.WebControls.DataGridItemEventHandler (this.dgrid_ItemCreated);

dgrid.SelectedIndexChanged+=new System.EventHandler(this.dgrid_SelectedIndexChange d);

dgrid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgrid_Edit);

dgrid.DeleteCommand+= new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgrid_Delete);

dgrid.PageIndexChanged+=new System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.dgrid_PageIndexChanged);



PlaceHolder1.Controls.Add(dgrid);

dgrid.DataBind();