Solved

Adding ItemTemplate to a TemplateColumn at run time

Posted on 2004-09-21
5
4,601 Views
Last Modified: 2012-08-13
Here we go brain-trust,
I am trying to add a ItemTemplate containing a hyperlink to a datagrid during run time.
I keep getting this error:
Object reference not set to an instance of an object

On this line:
Line 304:            .ItemTemplate.InstantiateIn(hlChoose)

In this code:
    Private Function POGrid(ByVal ds As DataSet)

        Dim bdPO As New BoundColumn
        bdPO.DataField = "t$pdno"
        bdPO.HeaderText = "PO#"
        'SO Column
        Dim bdSO As New BoundColumn
        bdSO.DataField = "t$orno"
        bdSO.HeaderText = "SO#"
        'Request Column
        Dim bdRequest As New BoundColumn
        bdRequest.DataField = "t$ddta"
        bdRequest.HeaderText = "Planned Ship Date"
        'Status Column

        'Link Column
        Dim tcLink As New TemplateColumn
        Dim hlChoose As New HyperLink
        Dim strHyper As String = "default.ecm.aspx?so="
        hlChoose.NavigateUrl = strHyper
        hlChoose.ID = "hlChoose"
        hlChoose.Text = "Correct"

        With tcLink
            .HeaderText = "Option"
            .ItemTemplate.InstantiateIn(hlChoose)
        End With

        tcLink.HeaderText = "Go To"
        With Me.dgExisting
            .AutoGenerateColumns = False
            .Columns.Add(bdPO)
            .Columns.Add(bdSO)
            .Columns.Add(bdRequest)
            .Columns.Add(tcLink)
            .DataSource = ds
            .DataBind()
            .Visible = True
            '.AllowPaging = True
            '.PageSize = 15

        End With

Along with that how do I assign the Field "t$orno" to Hyerlink.NaviagteURL
As you can see the dataset is being passed to this function. (Dataset filled by SQLDataAdapter)

I am pulling my hair out...lol
0
Comment
Question by:bmickey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:gsiric
ID: 12122481
HI,
you cant create template column on this way.
InstantiateIn is member of ITemplate interface, and method is called by the framework.
Parameter of InstantiateIn is not control which will be instatiated in container.
This is reference to the container.
This reference is used in implementig InstantiateIn when you implement ITemplate interface.

For details see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingtemplatesprogrammaticallyindatagridcontrol.asp


0
 

Author Comment

by:bmickey
ID: 12122918
I am confused, I saw an answer to a question that was very similar. Why will it work for him and not me.
Q_21016234.html
The big differnce I see is that I am using ADO.Net (SQLDataAdapter)  and he is using ADO (ADODB.Recordset ).
0
 

Author Comment

by:bmickey
ID: 12122993
What if I use a hyperlinkColumn?
0
 
LVL 7

Accepted Solution

by:
gsiric earned 400 total points
ID: 12123362
In this question his have CheckColumnTemplate which implement ITemplate.
And he define new repeater at runtime and instatiate Template in this repeater.


Repeater rptr = new Repeater();
CheckColumnTemplate col = new CheckColumnTemplate();
col.InstantiateIn(rptr);

you try to instantiate TemplateColumn in hyperlink.

You need to do (in C#):

public class HyperlinkColumnTemplate : ITemplate
{
    public void InstantiateIn(Control container)
  {
            HyperLink hl = new HyperLink();
            container.Controls.Add(hl);
   }
}



TemplateColumn tc = new TemplateColumn();
tc.ItemTemplate = new HyperLinkColumnTemplate();
...

and you dont need to call InstantiateIn.


0
 

Author Comment

by:bmickey
ID: 12124131
I was able to use HyperLinkColumn and a minor change to my my SQL Query to get the desired results at this time.

VB.Net Code
        Dim tcLink As New HyperLinkColumn

        With tcLink
            .HeaderText = "Go To"
            .DataNavigateUrlField = "address"
            .Text = "Go"
           
        End With

Trans-Act:
select t$orno,t$cuno,t$item,t$csgs,t$ddta,t$cprj,t$pdno,t$mitm,t$dscd, ('default.ecm.aspx?so=' + Convert(varchar(8),t$orno)) as Address from

Thank you for your help and the code. Knowledge I am sure I will use later
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question