473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

when to dynamically change datagrid column headers

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.A ssembly.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
}

Nov 19 '05 #1
2 6168
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
el********@hotmail.com

-----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, whenwill 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.GetExec utingAsse
mbly());

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
}

.

Nov 19 '05 #2
If you columns are autogenerated they are not listed in Columns collection.
The only place where you can catch them is ItemCreated event.

Eliyahu

"gh0st54" <gh*****@hotmail.com> wrote in message
news:SP*******************@weber.videotron.net...
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.A ssembly.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
}

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
4
by: IGotYourDotNet | last post by:
on my web app, i need to display data from a table in a grid. (i know how to do that). The grid will be populated with data depending on what the user selects in a drop down box. My question is...
0
by: gh0st54 | last post by:
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...
4
by: bill | last post by:
Can I add multiple datagrid controls dynamically at runtime? I want to break up my dataset into separate datagrids, so I can insert a "<p style="page-break-before: always"> tag between them. ...
3
by: david | last post by:
I have posted my question before. It seems that I can not find the solution. The question: I have datasource, say, ds which is bounded to a datagrid, dg. Assume that ds have 5 columns,...
1
by: ElenaR | last post by:
I need to figure out how to name my column headers in a DataGrid. In VB6, I could write DataGrid1.Columns(0).Caption = "ID". What is the format for VB.NET? Thanks in Advance!
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
0
by: kaushik.jaimalani | last post by:
Hi W3 Priority 1 checklist points for Table Header 5.2 For data tables that have two or more logical levels of row or column headers, use markup to associate data cells and header cells. ...
0
by: rn5a | last post by:
A DataGrid control displays records from a SQL Server 2005 DB table. The AllowSorting property of the DataGrid has been set to True & the SortExpressions of the BoundColumns have been set to the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.