gridview template column

G

Guest

hey all,
you know in the gridView quick task menu how you have the option of taking a
bound column and converting it into a TemplateColumn. Alright, once i do that
i goto edit the template column and then add a label (or any control) to the
itemTemplate, and then end the editing.

how can i do this dynamically in the code-behind. can someone please show me
a small example, for instance adding a label to a ItemTemplate

thanks,
rodchar
 
B

Beemer Biker

rodchar said:
hey all,
you know in the gridView quick task menu how you have the option of taking
a
bound column and converting it into a TemplateColumn. Alright, once i do
that
i goto edit the template column and then add a label (or any control) to
the
itemTemplate, and then end the editing.

how can i do this dynamically in the code-behind. can someone please show
me
a small example, for instance adding a label to a ItemTemplate

thanks,
rodchar

After converting to a template, go to the template and put in a panel, say
"ID_MyPanel". If there is anything in the template field (item or edit)
then delete it. There may already be a label there for you.

Anyway, at the callback

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}

you can find your panel with the following code:
Panel thisPanel = (Panel)e.Row.FindControl("ID_MyPanel");

once you found the panel you can add any controls you want, setting style
and attributes programmatically

HtmlImage thisSpectrum = new HtmlImage();
thisSpectrum.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid");
thisSpectrum.Style.Add(HtmlTextWriterStyle.BorderWidth, "1px");
thisSpectrum.Attributes.Add("title", "click here to see tits");
thisSpectrum.Attributes.Add("onclick", "return
SpectrumImages_onclick('juggs.jpg')");
thisPanel.Controls.Add(thisSpectrum);

The above adds an "html" Image and client side click handler, if you want a
"data" Image and server side just use "Image" instead. There is a code
snippet here where I finally figured out how to have a drop down list in one
column change the image in another.
all one server side.
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top