I cant get the item template to reflect the text of the selected item in the radcombobox that is in the edititemtemplate of my programmatically created gridtemplatecolumn
Code for creating the template column:
01.
Dim
tempDB
As
New
SqlDataSource
02.
Dim
templateColumnName
As
String
= col.Caption
03.
Dim
templateColumn
As
New
GridTemplateColumn()
04.
05.
templateColumn.DataField = col.Caption
06.
templateColumn.ItemTemplate =
New
LCDisp(templateColumnName, ddQuery, DiConnectionString)
07.
templateColumn.EditItemTemplate =
New
DDEdit(templateColumnName, ddQuery, DiConnectionString)
08.
templateColumn.HeaderText = templateColumnName
09.
10.
templateColumn.UniqueName = col.Caption
11.
12.
grdReport.Columns.Add(templateColumn)
Code for LCDisp template:
01.
Private
Class
LCDisp
02.
Implements
ITemplate
03.
Protected
lblCont
As
Label
04.
Private
colname
As
String
05.
Private
DSQuery
As
String
06.
Private
DiConnectionString
As
String
07.
08.
Public
Sub
New
(
ByVal
cName
As
String
,
ByVal
query
As
String
,
ByVal
connString
As
String
)
09.
colname = cName
10.
DSQuery = query
11.
DiConnectionString = connString
12.
End
Sub
13.
14.
Public
Sub
InstantiateIn(container
As
UI.Control)
Implements
ITemplate.InstantiateIn
15.
lblCont =
New
Label
16.
lblCont.ID =
"lControl"
+ colname
17.
AddHandler
lblCont.DataBinding,
AddressOf
litCont_DataBinding
18.
container.Controls.Add(lblCont)
19.
End
Sub
20.
21.
Sub
litCont_DataBinding(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
22.
Dim
l
As
Label =
DirectCast
(sender, Label)
23.
Dim
container
As
GridDataItem =
DirectCast
(l.NamingContainer, GridDataItem)
24.
l.Text = (
DirectCast
(container.DataItem, DataRowView))(colname).ToString()
25.
End
Sub
26.
End
Class
Code for DDEdit:
01.
Private
Class
DDEdit
02.
Implements
ITemplate
03.
Protected
DropDown
As
RadComboBox
04.
Private
colname
As
String
05.
Private
DSQuery
As
String
06.
Private
DiConnectionString
As
String
07.
Private
MyContainerDataItem
As
GridDataItem
08.
09.
Public
Sub
New
(
ByVal
cName
As
String
,
ByVal
query
As
String
,
ByVal
connString
As
String
)
10.
colname = cName
11.
DSQuery = query
12.
DiConnectionString = connString
13.
End
Sub
14.
15.
Public
Sub
InstantiateIn(container
As
UI.Control)
Implements
ITemplate.InstantiateIn
16.
DropDown =
New
RadComboBox
17.
18.
Dim
dv2
As
New
DataView
19.
Dim
oQuery
As
New
cWjCoQuery
20.
21.
oQuery.Load(DSQuery, ConfigurationManager.ConnectionStrings(DiConnectionString).ConnectionString)
22.
23.
Dim
tempDB
As
New
SqlDataSource
24.
tempDB.ID = colname +
"DB"
25.
26.
tempDB.SelectCommand = oQuery.SQLQuery
27.
tempDB.ConnectionString = ConfigurationManager.ConnectionStrings(DiConnectionString).ConnectionString
28.
29.
dv2 = tempDB.
Select
(DataSourceSelectArguments.Empty)
30.
DropDown.DataSource = tempDB
31.
If
dv2.Table.Columns.Count > 1
Then
32.
DropDown.DataTextField = dv2.Table.Columns.Item(0).Caption
33.
DropDown.DataValueField = dv2.Table.Columns.Item(1).Caption
34.
Else
35.
DropDown.DataTextField = dv2.Table.Columns.Item(0).Caption
36.
DropDown.DataValueField = dv2.Table.Columns.Item(0).Caption
37.
End
If
38.
39.
DropDown.DataBind()
40.
41.
MyContainerDataItem = TryCast(container.Parent, GridDataItem)
42.
If
MyContainerDataItem
Is
Nothing
Then
43.
MyContainerDataItem = TryCast(container.Parent.Parent, GridDataItem)
44.
End
If
45.
If
MyContainerDataItem IsNot
Nothing
Then
46.
Dim
tmpSelVal = MyContainerDataItem.GetDataKeyValue(colname).ToString
47.
If
Trim(tmpSelVal) <>
""
Then
48.
DropDown.SelectedIndex = DropDown.FindItemIndexByValue(
CInt
(tmpSelVal))
49.
End
If
50.
End
If
51.
52.
container.Controls.Add(DropDown)
53.
End
Sub
54.
End
Class