or
<
telerik:GridTemplateColumn
Display
=
"false"
UniqueName
=
"colClass"
HeaderText
=
"Class"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblClass"
Text=<%# Eval("Class") %> ></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"cbbClass"
DataSourceID
=
"classesDS"
OnSelectedIndexChanged
=
"cbbClass_SelectedIndexChanged"
AutoPostBack
=
"true"
EmptyMessage
=
"--Select a Class--"
Filter
=
"Contains"
DataValueField
=
"Class_ID"
DataTextField
=
"Class"
SelectedValue = <%# Eval("Class_ID") %> ></
telerik:RadComboBox
>
<
asp:RequiredFieldValidator
runat
=
"server"
ID
=
"cbbClassValidator"
ValidationGroup
=
"SessionSave"
ErrorMessage
=
"You must select a Class!"
Text
=
"*"
Display
=
"Dynamic"
ControlToValidate
=
"cbbClass"
></
asp:RequiredFieldValidator
>
<
asp:CompareValidator
runat
=
"server"
ID
=
"cbbClassValidator2"
ValueToCompare
=
""
Operator
=
"NotEqual"
ControlToValidate
=
"cbbClass"
Display
=
"Dynamic"
ErrorMessage
=
"You must select a Class2!"
Text
=
"*"
ValidationGroup
=
"SessionSave"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<%----------------------- DATA SOURCE FOR DELIVERABLE -------------------------%>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:ITSConnectionString %>"
DeleteCommand="DELETE FROM [Deliverable] WHERE [DeliverableId] = @DeliverableId"
InsertCommand="INSERT INTO [Deliverable] ([DeliverableTitle],[CCIds]) VALUES (@DeliverableTitle, @CCIds)"
SelectCommand="SELECT * FROM [Deliverable] WHERE ([DeliverableId] = @DeliverableId)"
UpdateCommand="UPDATE [Deliverable] SET [DeliverableTitle] = @DeliverableTitle, [CCIds] = @CCIds WHERE [DeliverableId] = @DeliverableId">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"DeliverableId"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"DeliverableId"
Type
=
"int32"
/>
<
asp:Parameter
Name
=
"DeliverableTitle"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CCIds"
Type
=
"String"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"DeliverableId"
Type
=
"int32"
/>
<
asp:Parameter
Name
=
"DeliverableTitle"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CCIds"
Type
=
"String"
/>
</
UpdateParameters
>
<
SelectParameters
>
<
asp:QueryStringParameter
Name
=
"DeliverableId"
QueryStringField
=
"DeliverableId"
Type
=
"Int32"
/>
</
SelectParameters
>
</
asp:SqlDataSource
>
<%----------------------- DATA SOURCE FOR COMBOBOX -------------------------%>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:ITSConnectionString %>" SelectCommand="SELECT [UserId], [DisplayName] FROM [Users]"></
asp:SqlDataSource
>
<%----------------------- THE DETAILS VIEW -------------------------%>
<
asp:DetailsView
ID
=
"DetailsView1"
runat
=
"server"
DefaultMode
=
"Insert"
AutoGenerateRows
=
"False"
DataKeyNames
=
"DeliverableId"
DataSourceID
=
"SqlDataSource2"
Height
=
"50px"
Width
=
"125px"
OnItemInserting
=
"DetailsView1_ItemInserting"
OnDataBinding
=
"DetailsView1_DataBinding"
OnDataBound
=
"DetailsView1_DataBound"
>
<
Fields
>
<
asp:BoundField
DataField
=
"DeliverableId"
HeaderText
=
"DeliverableId"
InsertVisible
=
"False"
ReadOnly
=
"True"
SortExpression
=
"DeliverableId"
/>
<
asp:BoundField
DataField
=
"DeliverableId"
HeaderText
=
"DeliverableId"
SortExpression
=
"DeliverableId"
/>
<
asp:BoundField
DataField
=
"DeliverableTitle"
HeaderText
=
"DeliverableTitle"
SortExpression
=
"DeliverableTitle"
/>
<
asp:TemplateField
>
<
ItemTemplate
>
<
telerik:RadComboBox
ID
=
"CCIds"
Text='<% #Bind("CCIds") %>' runat="server"
DataSourceID="SqlDataSource1" DataTextField="DisplayName" DataValueField="UserId"
CheckBoxes="true"></
telerik:RadComboBox
>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:CommandField
ShowEditButton
=
"True"
/>
<
asp:ButtonField
Text
=
"Insert"
CommandName
=
"Insert"
/>
<
asp:ButtonField
Text
=
"Update"
CommandName
=
"Update"
/>
</
Fields
>
</
asp:DetailsView
>
public
string
GetCheckBoxValues(
string
RadComboBoxName)
{
RadComboBox rcb = (RadComboBox)DetailsView1.FindControl(RadComboBoxName);
var collection = rcb.CheckedItems;
StringBuilder sbValues =
new
StringBuilder();
if
(collection.Count != 0)
{
foreach
(var item
in
collection)
{
sbValues.Append(item.Value);
sbValues.Append(Delimiter);
}
if
(sbValues.ToString().EndsWith(Delimiter))
sbValues.Remove(sbValues.Length - 1, 1);
}
return
sbValues.ToString();
}
// Get the comma separate values and insert them into the DB.
protected
void
DetailsView1_ItemInserting(
object
sender, DetailsViewInsertEventArgs e)
{
string
CCIds = GetCheckBoxValues(
"CCIds"
);
if
(CCIds !=
null
)
{
e.Values[
"CCIds"
] = CCIds;
}
}