473,394 Members | 1,645 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,394 software developers and data experts.

Dynamic Template in Datagrid using VB.NET

I have successfully built a datatable and datagrid for a
user-selectable field interface. The user can select the fields they
want, and the controlling table has the data type information. I can
format the dates as I want by using the DataFormatString property of
the BoundColumn. That's because the grid sees the data as a date and
knows what to do with it. Now I want to format a phone number that was
stored as a string from 8005551212 as (800)555-1212 and I want to
format an ID number also stored as a string from 0987654321 to
09-87654-321. The biggest reason is to be able to export to MS Excel,
and if you have ever tried exporting data with leading zeros, and all
numbers, Excel is quite happy to convert it to a number, and drop the
leading zero. That, of course, after it converts it to scientific
notation!!!

I have found reference to templates, but no decent documentation that
shows how to dynamically create them, on the VB side.

Any examples out there?

Nov 19 '05 #1
1 3631
Hi John,

Welcome to MSDN newsgroup.
From your description, you're developing a dynamic fields datagrid web page
which need to format some string based id or phone number. So you're
wondering how to do this through asp.net datagrid's TemplateColumn and make
it programmatical, yes?

If so , I think we can do it through the following steps:

1. As for formatting string through TemplateColumns, we can define some
helper function to do the formatting work and use thiese functions in the
TEmplateColumns' ItemTemplate, for example:
.............

<asp:TemplateColumn HeaderText="ID">
<ItemTemplate>
<%# FormatID(Container.DataItem(0)) %>
</ItemTemplate>
..................

FormatID function is defined in page as public member function:

Public Function FormatID(ByVal id As String)
Return String.Format("({0}){1}-{2}", id.Substring(0, 3),
id.Substring(3, 3), id.Substring(6, 4))
End Function

we can also make it as a Shared(static) function of a certain helper class

2. To make the above TemplateColumns programmatically, we can define a
Custom Template class implemeting the ITemplate interface. The following
MSDN reference as describing this:

#Creating Templates Programmatically in the DataGrid Control
http://msdn.microsoft.com/library/en...ngTemplatesPro
grammaticallyInDataGridControl.asp?frame=true

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
0
by: Andrea Trevisan | last post by:
That's a revival of a known thing I suppose.I hope it's useful. My problem was: I want to have a DataGrid with two Template columns: first with TextBox,second with Button.I want to fire an event...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm trying to add LinkButtons to a Repeater control using adynamic template. The docs state that you should be able tobubble the click event to the containing Repeater. There areplenty of examples in...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
0
by: tafpin | last post by:
I have an application with a datagrid. In the IDE I have 2 template columns. The first has an image button and the second contains a link button. According to the results that I get back I must...
2
by: Tumurbaatar S. | last post by:
I dynamically add columns to DataGrid as described in MSDN articles "Top Questions about the DataGrid Web Server Control" and "Creating Web Server Control Templates Programmatically". The columns...
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....
1
by: mitramay | last post by:
I am creating a dynamic datagrid. The controls in some of the template columns will have to be generated based on the data contained in them (i.e. the data for that respective DataField column)....
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.