473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

gridview template column

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
2 8623

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
9
by: hazz | last post by:
I want to display 'n' records for a table-driven data entry page. The first column should be readonly and the 2nd column, a checkbox WRITABLE (NOT READONLY). I can't use the gridview because it...
13
by: AG | last post by:
I have a gridview that I bind to a List(of Type) at runtime. Not using a datasource control. The gridview has a template column with an imagebutton whose commandname is set to 'Delete'. The...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview with several template columns and a few command button columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column 4 is a text box, followed by command button...
4
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.