when to dynamically change datagrid column headers

G

gh0st54

hi

still working on changing my data grid headers using resource files

the thing is i always gat a count of 0 for my datagrid columns count, when
will i get the columns count and when should i change the headers ??

thanks

private void Page_Load(object sender, System.EventArgs e)

{

this.sqlDataAdapter1.Fill(this.emp1,"Employees");

this.DataGrid1.DataBind();

Response.Write("columns :" + this.DataGrid1.Columns.Count);

// Put user code to initialize the page here

SetUI();

if(!Page.IsPostBack)

{

this.txtCulture.Text = Thread.CurrentThread.CurrentCulture.Name;

}

private void SetUI()

{

double d = 10.25;



Thread.CurrentThread.CurrentCulture = new
CultureInfo(this.txtCulture.Text);

Thread.CurrentThread.CurrentUICulture =
Thread.CurrentThread.CurrentCulture;


ResourceManager rm = new
ResourceManager("Demo.Strings",System.Reflection.Assembly.GetExecutingAssemb
ly());



if(Page.Controls.Count>1){

foreach( System.Web.UI.Control ctrl in
Page.FindControl("Form1").Controls) {


this.lblIds.Text += "<br/>Control : " + ctrl.ClientID.ToString()
+ " Control type" + ctrl.GetType().ToString();

//Response.Write();

if (ctrl.GetType().ToString() ==
"System.Web.UI.WebControls.DataGrid"){

DataGrid dg = (System.Web.UI.WebControls.DataGrid )ctrl;

foreach (DataGridColumn col in dg.Columns){


this.lblIds.Text += " <br/> Column header text :" +
col.HeaderText ;

}

}


}

}


// then use rm to set text


}
 
E

Elton Wang

It seems you don't really set data source for the datagrid.

It should be

this.sqlDataAdapter1.Fill(this.emp1,"Employees");
// You miss next line!
this.DataGrid1.DataSource = this.emp1;

this.DataGrid1.DataBind();
//...

Hope it helps,

Elton Wang
(e-mail address removed)

-----Original Message-----
hi

still working on changing my data grid headers using resource files

the thing is i always gat a count of 0 for my datagrid columns count, when
will i get the columns count and when should i change the headers ??

thanks

private void Page_Load(object sender, System.EventArgs e)

{

this.sqlDataAdapter1.Fill(this.emp1,"Employees");

this.DataGrid1.DataBind();

Response.Write("columns :" + this.DataGrid1.Columns.Count);

// Put user code to initialize the page here

SetUI();

if(!Page.IsPostBack)

{

this.txtCulture.Text = Thread.CurrentThread.CurrentCulture.Name;

}

private void SetUI()

{

double d = 10.25;



Thread.CurrentThread.CurrentCulture = new
CultureInfo(this.txtCulture.Text);

Thread.CurrentThread.CurrentUICulture =
Thread.CurrentThread.CurrentCulture;


ResourceManager rm = new
ResourceManager ("Demo.Strings",System.Reflection.Assembly.GetExecutingAsse
mb
ly());



if(Page.Controls.Count>1){

foreach( System.Web.UI.Control ctrl in
Page.FindControl("Form1").Controls) {


this.lblIds.Text += "<br/>Control : " + ctrl.ClientID.ToString()
+ " Control type" + ctrl.GetType().ToString();

//Response.Write();

if (ctrl.GetType().ToString() ==
"System.Web.UI.WebControls.DataGrid"){

DataGrid dg =
(System.Web.UI.WebControls.DataGrid )ctrl;
 
E

Eliyahu Goldin

If you columns are autogenerated they are not listed in Columns collection.
The only place where you can catch them is ItemCreated event.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top