Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > when to dynamically change datagrid column headers

Reply
Thread Tools

when to dynamically change datagrid column headers

 
 
gh0st54
Guest
Posts: n/a
 
      01-30-2005
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


}



 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      01-31-2005
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
http://www.velocityreviews.com/forums/(E-Mail 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.GetExec utingAsse
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;
>
> foreach (DataGridColumn col in dg.Columns)

{
>
>
> this.lblIds.Text += " <br/> Column

header text :" +
>col.HeaderText ;
>
> }
>
> }
>
>
> }
>
> }
>
>
> // then use rm to set text
>
>
>}
>
>
>
>.
>

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      01-31-2005
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" <(E-Mail Removed)> wrote in message
news:SPdLd.7019$(E-Mail Removed)...
> 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
>
>
> }
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid - each item having two headers one displayed by row another by column Krishna ASP .Net 0 07-13-2006 07:36 AM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Freezing Datagrid Column Headers =?Utf-8?B?Sm9obiBXYWxrZXI=?= ASP .Net 2 01-18-2006 08:38 PM
when to dynamically change datagrid column headers gh0st54 ASP .Net 0 01-30-2005 11:13 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM



Advertisments