Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding ItemTemplate to a TemplateColumn at run time

Posted on 2004-09-21
5
Medium Priority
?
4,622 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 1600 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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