Re: Changing datagrid column name dynamically

I

Ignacio Machin

Hi ,

What you mean with the column name?

The DataGrid.Columns is a collection of DataGridColumn's derived classes,
what you can change is the HeaderText property of it.

You cannot access a column by name, only by index.

Hope this help,
 
G

Guest

I'm not sure I understand.

I have this code:
DataSet DSAtt = new DataSet();
OdbcDataAdapter DA2 = new OdbcDataAdapter(mySql2, myConnection);
DA2.Fill(DSAtt, "pearht");
DataGridAttendance.DataSource = DSAtt.Tables["pearht"];
DataGridAttendance.DataBind();

What would I need to add to change the Header text of each of these columns?
Thanks.
 
I

Ignacio Machin

Hi,

You can use the DataGrid.Columns[ index].HeaderText

You will have to do it AFTER you call DataBind()

Pd:
If you are using TemplateColumn as the columns you better use the
<HeaderTemplate> section in the aspx page.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

I'm not sure I understand.

I have this code:
DataSet DSAtt = new DataSet();
OdbcDataAdapter DA2 = new OdbcDataAdapter(mySql2, myConnection);
DA2.Fill(DSAtt, "pearht");
DataGridAttendance.DataSource = DSAtt.Tables["pearht"];
DataGridAttendance.DataBind();

What would I need to add to change the Header text of each of these columns?
Thanks.


Ignacio Machin said:
Hi ,

What you mean with the column name?

The DataGrid.Columns is a collection of DataGridColumn's derived classes,
what you can change is the HeaderText property of it.

You cannot access a column by name, only by index.

Hope this help,
 
G

Guest

I tried that before (with the example you gave me on how to change column
height) but I get :

Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index

To change one column, I use
DataGridAttendance.Columns[0].HeaderText = "From Date";


Ignacio Machin said:
Hi,

You can use the DataGrid.Columns[ index].HeaderText

You will have to do it AFTER you call DataBind()

Pd:
If you are using TemplateColumn as the columns you better use the
<HeaderTemplate> section in the aspx page.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

I'm not sure I understand.

I have this code:
DataSet DSAtt = new DataSet();
OdbcDataAdapter DA2 = new OdbcDataAdapter(mySql2, myConnection);
DA2.Fill(DSAtt, "pearht");
DataGridAttendance.DataSource = DSAtt.Tables["pearht"];
DataGridAttendance.DataBind();

What would I need to add to change the Header text of each of these columns?
Thanks.


Ignacio Machin said:
Hi ,

What you mean with the column name?

The DataGrid.Columns is a collection of DataGridColumn's derived classes,
what you can change is the HeaderText property of it.

You cannot access a column by name, only by index.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


<VM> wrote in message How can I change the column name of a datagrid dynamically?
Thanks.
 
G

Guest

The columns are automatically generated depending on the result of my query.
I'm not declaring any columns.

I tried to rename the column names in the Oracle select but the ODBC driver
doesn't recognize it.

VM


Ignacio Machin said:
Hi

Are you declaring your columns ?
If they are automatically generated you can not use Columns for this.

How are you defining your grid in the aspx page?

From MSDN:
Explicitly declared columns may be used in conjunction with automatically
generated columns. When using both, explicitly declared columns will be
rendered first, followed by the automatically generated columns.
Automatically generated columns are not added to the Columns collection.


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

I tried that before (with the example you gave me on how to change column
height) but I get :

Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index

To change one column, I use
DataGridAttendance.Columns[0].HeaderText = "From Date";


Ignacio Machin said:
Hi,

You can use the DataGrid.Columns[ index].HeaderText

You will have to do it AFTER you call DataBind()

Pd:
If you are using TemplateColumn as the columns you better use the
<HeaderTemplate> section in the aspx page.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<VM> wrote in message I'm not sure I understand.

I have this code:
DataSet DSAtt = new DataSet();
OdbcDataAdapter DA2 = new OdbcDataAdapter(mySql2, myConnection);
DA2.Fill(DSAtt, "pearht");
DataGridAttendance.DataSource = DSAtt.Tables["pearht"];
DataGridAttendance.DataBind();

What would I need to add to change the Header text of each of these
columns?
Thanks.


"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
Hi ,

What you mean with the column name?

The DataGrid.Columns is a collection of DataGridColumn's derived
classes,
what you can change is the HeaderText property of it.

You cannot access a column by name, only by index.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


<VM> wrote in message How can I change the column name of a datagrid dynamically?
Thanks.
 
I

Ignacio Machin

Hi,

Try to set the columns as this in the ASP.NET page:

<Columns>

<asp:BoundColumn
HeaderText="Item"
DataField="StringValue"/>

<asp:BoundColumn
HeaderText="Price"
DataField="CurrencyValue"
DataFormatString="{0:c}">

<ItemStyle HorizontalAlign="right">
</ItemStyle>

</asp:BoundColumn>

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



The columns are automatically generated depending on the result of my query.
I'm not declaring any columns.

I tried to rename the column names in the Oracle select but the ODBC driver
doesn't recognize it.

VM


Ignacio Machin said:
Hi

Are you declaring your columns ?
If they are automatically generated you can not use Columns for this.

How are you defining your grid in the aspx page?

From MSDN:
Explicitly declared columns may be used in conjunction with automatically
generated columns. When using both, explicitly declared columns will be
rendered first, followed by the automatically generated columns.
Automatically generated columns are not added to the Columns collection.


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

I tried that before (with the example you gave me on how to change column
height) but I get :

Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index

To change one column, I use
DataGridAttendance.Columns[0].HeaderText = "From Date";


"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
Hi,

You can use the DataGrid.Columns[ index].HeaderText

You will have to do it AFTER you call DataBind()

Pd:
If you are using TemplateColumn as the columns you better use the
<HeaderTemplate> section in the aspx page.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<VM> wrote in message I'm not sure I understand.

I have this code:
DataSet DSAtt = new DataSet();
OdbcDataAdapter DA2 = new OdbcDataAdapter(mySql2, myConnection);
DA2.Fill(DSAtt, "pearht");
DataGridAttendance.DataSource = DSAtt.Tables["pearht"];
DataGridAttendance.DataBind();

What would I need to add to change the Header text of each of these
columns?
Thanks.


"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
Hi ,

What you mean with the column name?

The DataGrid.Columns is a collection of DataGridColumn's derived
classes,
what you can change is the HeaderText property of it.

You cannot access a column by name, only by index.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


<VM> wrote in message How can I change the column name of a datagrid dynamically?
Thanks.
 
V

VM

I'm going to check the code you sent me right now.

Thanks for al your help,
Vaughn

Ignacio Machin said:
Hi,

Try to set the columns as this in the ASP.NET page:

<Columns>

<asp:BoundColumn
HeaderText="Item"
DataField="StringValue"/>

<asp:BoundColumn
HeaderText="Price"
DataField="CurrencyValue"
DataFormatString="{0:c}">

<ItemStyle HorizontalAlign="right">
</ItemStyle>

</asp:BoundColumn>

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



The columns are automatically generated depending on the result of my query.
I'm not declaring any columns.

I tried to rename the column names in the Oracle select but the ODBC driver
doesn't recognize it.

VM


Ignacio Machin said:
Hi

Are you declaring your columns ?
If they are automatically generated you can not use Columns for this.

How are you defining your grid in the aspx page?

From MSDN:
Explicitly declared columns may be used in conjunction with automatically
generated columns. When using both, explicitly declared columns will be
rendered first, followed by the automatically generated columns.
Automatically generated columns are not added to the Columns collection.


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<VM> wrote in message I tried that before (with the example you gave me on how to change column
height) but I get :

Index was out of range. Must be non-negative and less than the size
of
the
collection. Parameter name: index

To change one column, I use
DataGridAttendance.Columns[0].HeaderText = "From Date";


"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
Hi,

You can use the DataGrid.Columns[ index].HeaderText

You will have to do it AFTER you call DataBind()

Pd:
If you are using TemplateColumn as the columns you better use the
<HeaderTemplate> section in the aspx page.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<VM> wrote in message I'm not sure I understand.

I have this code:
DataSet DSAtt = new DataSet();
OdbcDataAdapter DA2 = new OdbcDataAdapter(mySql2, myConnection);
DA2.Fill(DSAtt, "pearht");
DataGridAttendance.DataSource = DSAtt.Tables["pearht"];
DataGridAttendance.DataBind();

What would I need to add to change the Header text of each of these
columns?
Thanks.


"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
Hi ,

What you mean with the column name?

The DataGrid.Columns is a collection of DataGridColumn's derived
classes,
what you can change is the HeaderText property of it.

You cannot access a column by name, only by index.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


<VM> wrote in message
How can I change the column name of a datagrid dynamically?
Thanks.
 

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

Top