Solved

Adding ItemTemplate to a TemplateColumn at run time

Posted on 2004-09-21
5
4,606 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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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