473,665 Members | 2,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(objec t sender, System.EventArg s e)

{

this.sqlDataAda pter1.Fill(this .emp1,"Employee s");

this.DataGrid1. DataBind();

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

// Put user code to initialize the page here

SetUI();

if(!Page.IsPost Back)

{

this.txtCulture .Text = Thread.CurrentT hread.CurrentCu lture.Name;

}

private void SetUI()

{

double d = 10.25;

Thread.CurrentT hread.CurrentCu lture = new
CultureInfo(thi s.txtCulture.Te xt);

Thread.CurrentT hread.CurrentUI Culture =
Thread.CurrentT hread.CurrentCu lture;
ResourceManager rm = new
ResourceManager ("Demo.Strings" ,System.Reflect ion.Assembly.Ge tExecutingAssem b
ly());

if(Page.Control s.Count>1){

foreach( System.Web.UI.C ontrol ctrl in
Page.FindContro l("Form1").Cont rols) {
this.lblIds.Tex t += "<br/>Control : " + ctrl.ClientID.T oString()
+ " Control type" + ctrl.GetType(). ToString();

//Response.Write( );

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

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

foreach (DataGridColumn col in dg.Columns){
this.lblIds.Tex t += " <br/> Column header text :" +
col.HeaderText ;

}

}
}

}
// then use rm to set text
}

Nov 19 '05 #1
2 6196
It seems you don't really set data source for the datagrid.

It should be

this.sqlDataAda pter1.Fill(this .emp1,"Employee s");
// You miss next line!
this.DataGrid1. DataSource = this.emp1;

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

Hope it helps,

Elton Wang
el********@hotm ail.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(objec t sender, System.EventArg s e)

{

this.sqlDataAd apter1.Fill(thi s.emp1,"Employe es");

this.DataGrid1 .DataBind();

Response.Write ("columns :" + this.DataGrid1. Columns.Count);
// Put user code to initialize the page here

SetUI();

if(!Page.IsPos tBack)

{

this.txtCultur e.Text = Thread.CurrentT hread.CurrentCu lture.Name;
}

private void SetUI()

{

double d = 10.25;

Thread.CurrentT hread.CurrentCu lture = new
CultureInfo(th is.txtCulture.T ext);

Thread.CurrentT hread.CurrentUI Culture =
Thread.Current Thread.CurrentC ulture;
ResourceManager rm = new
ResourceManage r ("Demo.Strings" ,System.Reflect ion.Assembly.Ge tExecutingAsse
mbly());

if(Page.Control s.Count>1){

foreach( System.Web.UI.C ontrol ctrl in
Page.FindContr ol("Form1").Con trols) {
this.lblIds.Tex t += "<br/>Control : " + ctrl.ClientID.T oString()+ " Control type" + ctrl.GetType(). ToString();

//Response.Write( );

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

DataGrid dg = (System.Web.UI. WebControls.Dat aGrid )ctrl;
foreach (DataGridColumn col in dg.Columns) {

this.lblIds.Tex t += " <br/> Column header text :" +col.HeaderTe xt ;

}

}
}

}
// 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*****@hotmai l.com> wrote in message
news:SP******** ***********@web er.videotron.ne t...
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(objec t sender, System.EventArg s e)

{

this.sqlDataAda pter1.Fill(this .emp1,"Employee s");

this.DataGrid1. DataBind();

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

// Put user code to initialize the page here

SetUI();

if(!Page.IsPost Back)

{

this.txtCulture .Text = Thread.CurrentT hread.CurrentCu lture.Name;

}

private void SetUI()

{

double d = 10.25;

Thread.CurrentT hread.CurrentCu lture = new
CultureInfo(thi s.txtCulture.Te xt);

Thread.CurrentT hread.CurrentUI Culture =
Thread.CurrentT hread.CurrentCu lture;
ResourceManager rm = new
ResourceManager ("Demo.Strings" ,System.Reflect ion.Assembly.Ge tExecutingAssem b ly());

if(Page.Control s.Count>1){

foreach( System.Web.UI.C ontrol ctrl in
Page.FindContro l("Form1").Cont rols) {
this.lblIds.Tex t += "<br/>Control : " + ctrl.ClientID.T oString() + " Control type" + ctrl.GetType(). ToString();

//Response.Write( );

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

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

foreach (DataGridColumn col in dg.Columns){
this.lblIds.Tex t += " <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
7904
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 header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the same control. Is there anyone who has tried this before and knows why this is hapenning ??
4
2032
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 instead of having 20 grids can i use only 1 and change the data that should be displayed and the headers via code, or do I need a seperate grid per choice in the drop down box.
0
399
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 change the headers ?? thanks private void Page_Load(object sender, System.EventArgs e)
4
2418
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. The objective is for the user to be able to print the data with pagebreaks and column headers on each printed page. Thanks
3
1844
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, c0,c1,c2,c3,c4. In some case, say, case 1, I want to display columns c0, c1,c2 in dg and use c3 and c4 in code behind. In case 2, I want to display column c0, c3, and c4, and use c1 and c2 in code behind. The following Possible solution do not work:
1
10231
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
5047
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, websites, MSDN and was not able to find something that would help me understand and code. I might not be searching for the right words or phrases. So if you know how to do this or know of links or websites that have information about this, please...
0
1066
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. 5.2 point says that data cells should associate with the column header. How can i achieve the above requirement in ASP.Net datagrid control?
0
1334
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 different columns so that users can sort the DataGrid by clicking the headers in the DataGrid. The DataGrid can be sorted using all the headers in the DataGrid except for the first column header. <asp:DataGrid ID="dg1" AllowSorting="true"...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7376
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.