Hi,
I'm trying to use a grid to display Facilities and Contacts. A 'Facility' would be something like a factory, office or location and there is a parent/child relationship between the two.
In my DetailTable, I would like the user to be able to add a new contact. When the 'Add new record' link is clicked, I would like to fill a combobox with contacts that are NOT currently assigned to the Facility.
I'm using the following thread as a guide.
http://www.telerik.com/community/forums/aspnet-ajax/grid/fill-datasource-in-radcombobox-within-edititemtemplate-of-radgrid.aspx
I'm trying to use the ItemDataBound event to fill my combobox. The problem that I have is that I'm unable to find a reference to the FacilityID in this method. I've tried using insertItem.ParentItem but this is null when I try and read it in debug mode.
Can someone point me in the right direction?
Thanks,
Tim
I'm trying to use a grid to display Facilities and Contacts. A 'Facility' would be something like a factory, office or location and there is a parent/child relationship between the two.
In my DetailTable, I would like the user to be able to add a new contact. When the 'Add new record' link is clicked, I would like to fill a combobox with contacts that are NOT currently assigned to the Facility.
I'm using the following thread as a guide.
http://www.telerik.com/community/forums/aspnet-ajax/grid/fill-datasource-in-radcombobox-within-edititemtemplate-of-radgrid.aspx
I'm trying to use the ItemDataBound event to fill my combobox. The problem that I have is that I'm unable to find a reference to the FacilityID in this method. I've tried using insertItem.ParentItem but this is null when I try and read it in debug mode.
Can someone point me in the right direction?
Thanks,
Tim
Protected
Sub
RadGrid1_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
RadGrid1.ItemDataBound
If
(
TypeOf
e.Item
Is
GridEditFormInsertItem)
AndAlso
(e.Item.OwnerTableView.IsItemInserted)
Then
Dim
insertItem
As
GridEditFormInsertItem =
DirectCast
(e.Item, GridEditFormInsertItem)
Dim
combo
As
DropDownList =
DirectCast
(insertItem(
"colContactId"
).FindControl(
"cboContactID"
), DropDownList)
Dim
conn
As
New
SqlConnection(connectionstring)
conn.Open()
'How do I reference FacilityID from the line below????
Dim
adp
As
New
SqlDataAdapter(
"SELECT ContactName,ContactID from Contacts WHERE ContactID NOT IN (Select ContactID From FacilityContacts WHERE FacilityID=<NeedHelpHere>"
, conn)
Dim
dt
As
New
DataTable()
adp.Fill(dt)
combo.DataSource = dt
combo.DataTextField =
"ContactName"
combo.DataValueField =
"ContactID"
combo.DataBind()
conn.Close()
End
If
End
Sub
<
telerik:RadGrid
ID
=
"RadGrid1"
ShowStatusBar
=
"True"
DataSourceID
=
"dsFacilityList"
runat
=
"server"
PageSize
=
"7"
AllowSorting
=
"True"
AllowPaging
=
"True"
GridLines
=
"None"
CellSpacing
=
"0"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
>
<
PagerStyle
Mode
=
"NumericPages"
></
PagerStyle
>
<
MasterTableView
DataSourceID
=
"dsFacilityList"
AllowMultiColumnSorting
=
"True"
PageSize
=
"20"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"FacilityID"
EditMode
=
"EditForms"
>
<
EditItemTemplate
>
</
EditItemTemplate
>
<
DetailTables
>
<
telerik:GridTableView
runat
=
"server"
DataKeyNames
=
"FacilityID"
DataSourceID
=
"dsFacilityContactList2"
CommandItemDisplay
=
"Top"
AutoGenerateColumns
=
"False"
>
<
EditItemTemplate
>
</
EditItemTemplate
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"FacilityID"
MasterKeyField
=
"FacilityID"
/>
</
ParentTableRelation
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
/>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
/>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
/>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridTemplateColumn
DataField
=
"ContactID"
FilterControlAltText
=
"Filter column column"
UniqueName
=
"colContactId"
>
<
EditItemTemplate
>
Contact ID <
asp:TextBox
ID
=
"ContactIDTextBox"
runat
=
"server"
Text='<%# Bind("ContactID") %>'></
asp:TextBox
>
<
asp:DropDownList
ID
=
"cboContactID"
runat
=
"server"
>
</
asp:DropDownList
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"ContactIDLabel"
runat
=
"server"
Text='<%# Eval("ContactID") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"FacilityID"
FilterControlAltText
=
"Filter column1 column"
UniqueName
=
"column1"
>
<
EditItemTemplate
>
Facility ID <
asp:TextBox
ID
=
"FacilityIDTextBox"
runat
=
"server"
Text='<%# Bind("FacilityID") %>'></
asp:TextBox
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"FacilityIDLabel"
runat
=
"server"
Text='<%# Eval("FacilityID") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
telerik:GridTableView
>
</
DetailTables
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
Visible
=
"True"
>
</
ExpandCollapseColumn
>
<
SortExpressions
>
</
SortExpressions
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
>
</
HeaderContextMenu
>
</
telerik:RadGrid
>