bmickey
asked on
Adding ItemTemplate to a TemplateColumn at run time
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.InstantiateI n(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.InstantiateI n(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
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.InstantiateI
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.InstantiateI
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
ASKER
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 ).
Q_21016234.html
The big differnce I see is that I am using ADO.Net (SQLDataAdapter) and he is using ADO (ADODB.Recordset ).
ASKER
What if I use a hyperlinkColumn?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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$csg s,t$ddta,t $cprj,t$pd no,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
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$csg
Thank you for your help and the code. Knowledge I am sure I will use later
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