By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,220 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,220 IT Pros & Developers. It's quick & easy.

gridview template column

P: n/a
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
Nov 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
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.BorderS tyle, "solid");
thisSpectrum.Style.Add(HtmlTextWriterStyle.BorderW idth, "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. news:12*************@corp.supernews.com
all one server side.

Nov 10 '06 #2

P: n/a
thank you, i'll give it a shot and report back with results. rod.

"Beemer Biker" wrote:
>
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
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.BorderS tyle, "solid");
thisSpectrum.Style.Add(HtmlTextWriterStyle.BorderW idth, "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. news:12*************@corp.supernews.com
all one server side.

Nov 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.