when to dynamically change datagrid column headers

Discussion in 'ASP .Net' started by gh0st54, Jan 30, 2005.

  1. gh0st54

    gh0st54 Guest

    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


    }
     
    gh0st54, Jan 30, 2005
    #1
    1. Advertising

  2. gh0st54

    Elton Wang Guest

    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



    >-----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;
    >
    > foreach (DataGridColumn col in dg.Columns)

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

    header text :" +
    >col.HeaderText ;
    >
    > }
    >
    > }
    >
    >
    > }
    >
    > }
    >
    >
    > // then use rm to set text
    >
    >
    >}
    >
    >
    >
    >.
    >
     
    Elton Wang, Jan 31, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:SPdLd.7019$...
    > 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
    >
    >
    > }
    >
    >
    >
     
    Eliyahu Goldin, Jan 31, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gh0st54
    Replies:
    0
    Views:
    394
    gh0st54
    Jan 30, 2005
  2. =?Utf-8?B?Sm9obiBXYWxrZXI=?=

    Freezing Datagrid Column Headers

    =?Utf-8?B?Sm9obiBXYWxrZXI=?=, Jan 18, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,966
    =?Utf-8?B?Sm9obiBXYWxrZXI=?=
    Jan 18, 2006
  3. Krishna
    Replies:
    0
    Views:
    525
    Krishna
    Jul 13, 2006
  4. James
    Replies:
    0
    Views:
    506
    James
    Sep 21, 2006
  5. Nathan Baulch
    Replies:
    1
    Views:
    145
    Nathan Baulch
    Sep 19, 2003
Loading...

Share This Page