473,804 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DataFormatStrin g 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 3655
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:TemplateCo lumn HeaderText="ID" >
<ItemTemplate >
<%# FormatID(Contai ner.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 programmaticall y, we can define a
Custom Template class implemeting the ITemplate interface. The following
MSDN reference as describing this:

#Creating Templates Programmaticall y in the DataGrid Control
http://msdn.microsoft.com/library/en...ngTemplatesPro
grammaticallyIn DataGridControl .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
3569
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) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
0
2807
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 from button and I want to have a reference to TextBox to make use of it.The most difficult was the reference to TextBox. This sample is taken from MCAD/MCSD Exam 70-305/70-315 of Microsoft Press.This book is much more exhaustive than the brief...
0
1999
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 the documentation for doing this using an<ItemTemplate> tag, but I haven't found any indication for howyou would do this in a dynamic template (implementing theITemplate interface). I'm adding the LInkButton in the TemplateDataBinding...
3
3989
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 step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
0
1759
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 add more columns to the datagrid. This is a sample of how I am adding these colums: templateColumn = New TemplateColumn
2
2229
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 are template based and all they use a same template producer. In the edit mode (ListItemType.EditItem) the template adds textbox and validator controls to a column as: public void InstantiateIn(System.Web.UI.Control container) { TextBox tb =...
3
13757
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. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
1
2048
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). For example, if I have a column called Available, the possible values for it are Yes or No. In case it is "Yes" I need a label in that column and in case it is "No" I need a hyperlink. Pls help.
0
2918
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 strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.