Hello,

I need help with my code,I'm showing 3 columns from a table in datase in a gridview and I want when I click on select button to show me the forth column for that row in a textbox.
this code,shows 3 columns in the gridview but when I click on a select I dont get the forth column.
I should mention that I don't want to show the forth column in the gridview I just want it to appear in textbox when I click on a select!

please tell me what else I should add to my code to make it work!




public class NewsWP : System.Web.UI.WebControls.WebParts.WebPart
{
Label messages;
GridView gridv;

SqlDataSource datasource;
SqlDataSource datasourceF;
TextBox txt1 = new TextBox();


public NewsWP()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();

// DatasSource
datasource = new SqlDataSource();
datasource.ID = "SqlDataSource1";

//DataSource for FormView
datasourceF = new SqlDataSource();
datasourceF.ID = "SqlDataSource2";

//GridView data Connection
datasource.ConnectionString = "Data Source =.\\sqlexpress;Initial Catalog=db;Integrated Security=SSPI; Integrated Security=True;Trusted_Connection=True;";
datasource.SelectCommand = "select Y,X,ID from table";
Controls.Add(datasource);

//otherGridView data Connection
datasourceF.ConnectionString = "Data Source =.\\sqlexpress;Initial Catalog=db;Integrated Security=SSPI; Integrated Security=True;Trusted_Connection=True;";
datasourceF.SelectCommand = "select T from table Where ID=@ID";
datasourceF.SelectParameters.Add(new ControlParameter("ID", "OuterGridView", "SelectedDataKey.Value"));
Controls.Add(datasourceF);


//GridView
gridv = new GridView();
gridv.AutoGenerateColumns = false;
gridv.Visible = true;
gridv.Width = Unit.Percentage(100);
gridv.GridLines = GridLines.Horizontal;
gridv.HeaderStyle.CssClass = "ms-vh2";
gridv.CellPadding = 4;
gridv.AllowPaging = true;
gridv.PageSize = 4;
gridv.DataKeyNames = new String[]{"ID"};
gridv.ID = "OuterGridView";
gridv.SelectedIndexChanged += new EventHandler(gridv_SelectedIndexChanged);
gridv.PagerTemplate = null;
gridv.AllowSorting = true;
gridv.AutoGenerateSelectButton = true;
Controls.Add(gridv);

gridv.DataSourceID = "SqlDataSource1";

//Add Grid columns
BoundField column;

column = new BoundField();
column.DataField = "Z";
column.HeaderText = "Z";
gridv.Columns.Add(column);

column = new BoundField();
column.DataField = "Y";
column.HeaderText = "Y";
column.HtmlEncode = false;
gridv.Columns.Add(column);
column = new BoundField();

//Add label
messages = new Label();
Controls.Add(messages);

}

void gridv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridv.PageIndex = e.NewPageIndex;
gridv.DataBind();
}

void gridv_SelectedIndexChanged(object sender, EventArgs e)
{
//throw new NotImplementedException();
GridViewRow row = gridv.SelectedRow;

//WHAT TO WRITE HERE TO SHOW THE 4rth COLUMN IN THE TEXTBOX?

}
}//end of class

class MyTemplatee : ITemplate
{

GridView myGridView;

#region ITemplate Members

public void InstantiateIn(Control container)
{
// throw new NotImplementedException();

TextBox t = new TextBox();
container.Controls.Add(t);


}

#endregion


protected void Page_Init(object sender, EventArgs e)
{
TemplateField t = new TemplateField();
t.HeaderText = "Dynamic";

MyTemplatee m = new MyTemplatee();
t.ItemTemplate = m;


GridView myGridView = new GridView();
myGridView.Columns.Add(t);
myGridView.DataSourceID = "SqlDataSource2";

}

}
}