changing the gridview header text

F

fredd00

hi
i'm trying to change the gridview columns header text

the columns are not auto generated, i have set specific headertext
values for each column

i want to change the header text based on the specific header text. i
want to load a new text from a global resource file.

what i'm actually trying to do and is not working :

protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header) //
DataControlRowType.DataRow
{
foreach (TableCell tc in e.Row.Cells)
{
string s =
(string)GetGlobalResourceObject("General", tc.Text);
if (s != null)
{
tc.Text = s;
}
}
}
}

the problem is that tc.Text is always ""
if i'm going through a DataControlRowType.DataRow there is text in
tc.Text

any idea when the header text if filled in ?
 
F

fredd00

Try RowCreated event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin


hi
i'm trying to change the gridview columns header text
the columns are not auto generated, i have set specific headertext
values for each column
i want to change the header text based on the specific header text. i
want to load a new text from a global resource file.
what i'm actually trying to do and is not working :
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header) //
DataControlRowType.DataRow
{
foreach (TableCell tc in e.Row.Cells)
{
string s =
(string)GetGlobalResourceObject("General", tc.Text);
if (s != null)
{
tc.Text = s;
}
}
}
}
the problem is that tc.Text is always ""
if i'm going through a DataControlRowType.DataRow there is text in
tc.Text
any idea when the header text if filled in ?

Hi

I did try the row created event but the tc.Text is always ""

any other idea ?
 
E

Eliyahu Goldin

How do you set the headers?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


fredd00 said:
Try RowCreated event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin


hi
i'm trying to change the gridview columns header text
the columns are not auto generated, i have set specific headertext
values for each column
i want to change the header text based on the specific header text. i
want to load a new text from a global resource file.
what i'm actually trying to do and is not working :
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header) //
DataControlRowType.DataRow
{
foreach (TableCell tc in e.Row.Cells)
{
string s =
(string)GetGlobalResourceObject("General", tc.Text);
if (s != null)
{
tc.Text = s;
}
}
}
}
the problem is that tc.Text is always ""
if i'm going through a DataControlRowType.DataRow there is text in
tc.Text
any idea when the header text if filled in ?

Hi

I did try the row created event but the tc.Text is always ""

any other idea ?
 
F

fredd00

How do you set the headers?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin


Try RowCreated event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin

hi
i'm trying to change the gridview columns header text
the columns are not auto generated, i have set specific headertext
values for each column
i want to change the header text based on the specific header text. i
want to load a new text from a global resource file.
what i'm actually trying to do and is not working :
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header) //
DataControlRowType.DataRow
{
foreach (TableCell tc in e.Row.Cells)
{
string s =
(string)GetGlobalResourceObject("General", tc.Text);
if (s != null)
{
tc.Text = s;
}
}
}
}
the problem is that tc.Text is always ""
if i'm going through a DataControlRowType.DataRow there is text in
tc.Text
any idea when the header text if filled in ?

I did try the row created event but the tc.Text is always ""
any other idea ?

they are in the grid view declaration

<Columns>
<asp:BoundField DataField="titre" HeaderText="Title"
SortExpression="titre" meta:resourcekey="BoundFieldResource1" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="description"
meta:resourcekey="BoundFieldResource2" />
<asp:BoundField DataField="Langue" HeaderText="Langue"
SortExpression="langue" meta:resourcekey="BoundFieldResource3" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Duree"
HeaderText="Duration" SortExpression="Duree"
meta:resourcekey="BoundFieldResource4" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="STD" HeaderText="STD"
SortExpression="std" meta:resourcekey="BoundFieldResource5" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ID_Offre" HeaderText="ID"
meta:resourcekey="BoundFieldResource6" />
</Columns>

when are the values inserted in the grid and when can i retrieve them ?
 
F

fredd00

How do you set the headers?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin


Try RowCreated event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldin

hi
i'm trying to change the gridview columns header text
the columns are not auto generated, i have set specific headertext
values for each column
i want to change the header text based on the specific header text. i
want to load a new text from a global resource file.
what i'm actually trying to do and is not working :
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header) //
DataControlRowType.DataRow
{
foreach (TableCell tc in e.Row.Cells)
{
string s =
(string)GetGlobalResourceObject("General", tc.Text);
if (s != null)
{
tc.Text = s;
}
}
}
}
the problem is that tc.Text is always ""
if i'm going through a DataControlRowType.DataRow there is text in
tc.Text
any idea when the header text if filled in ?

I did try the row created event but the tc.Text is always ""
any other idea ?


i set the header text in the gridview declaration

<Columns>
<asp:BoundField DataField="titre" HeaderText="Title"
SortExpression="titre" meta:resourcekey="BoundFieldResource1" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="description"
meta:resourcekey="BoundFieldResource2" />
<asp:BoundField DataField="Langue" HeaderText="Langue"
SortExpression="langue" meta:resourcekey="BoundFieldResource3" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Duree"
HeaderText="Duration" SortExpression="Duree"
meta:resourcekey="BoundFieldResource4" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="STD" HeaderText="STD"
SortExpression="std" meta:resourcekey="BoundFieldResource5" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ID_Offre" HeaderText="ID"
meta:resourcekey="BoundFieldResource6" />
</Columns>


when does the header text binding occur , when can i retrieve the
header text values ?
 
F

fredd00

here is my solution that works :

protected virtual void RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell cell in e.Row.Cells)
{
foreach (Control ctl in cell.Controls)
{
if (ctl.GetType() == typeof(LinkButton))
{
string s =
(string)GetGlobalResourceObject("General", "title");
if(s !=null)
{
((LinkButton)ctl).Text = s;
}
}
}
}

}
}
 
F

fredd00

oups her is the fixed one

protected virtual void RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[5].Visible = false;
//e.Row.Cells[5].Text = string.Empty;
e.Row.Cells[5].Width = Unit.Pixel(1);

foreach (TableCell cell in e.Row.Cells)
{
foreach (Control ctl in cell.Controls)
{
if (ctl.GetType() == typeof(LinkButton))
{
LinkButton btn = (LinkButton)ctl;
string s =
(string)GetGlobalResourceObject("General", btn.Text);
if(s !=null)
{
btn.Text = s;
}
}
}
}

}
}
 
F

fredd00

here is the fix

foreach (DataControlFieldCell cell in e.Row.Cells)
{
foreach (Control ctl in cell.Controls)
{
LinkButton link = ctl as LinkButton;
if (link != null)
{
string s =
(string)GetGlobalResourceObject("General", link.Text);
if (s != null)
{
link.Text = s;
}
}
}
}
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top