using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FRC
{
public partial class CheckBoxNullableChecked : System.Web.UI.UserControl
{
private bool m_checked = false;
protected void Page_Load(object sender, EventArgs e)
{
m_checked = CheckBox1.Checked;
}
public object Checked
{
get { return m_checked; }
set
{
if (value.GetType() == DBNull.Value.GetType()) m_checked = false;
else if (value == null) m_checked = false;
else if (value.GetType() == typeof(bool)) m_checked = (bool)value;
else m_checked = false;
}
}
public string Text
{
get { return this.CheckBox1.Text; }
set { this.CheckBox1.Text = value; }
}
protected void Page_PreRender()
{
CheckBox1.Checked = m_checked;
}
}
}
%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CheckBoxNullableChecked.ascx.cs" Inherits="FRC.CheckBoxNullableChecked" %>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
/>
<%@ Register src="~/CheckBoxNullableChecked.ascx" TagName="CheckBoxNullableChecked"
TagPrefix="uc1" %>
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
<
div
id
=
"divGridEdit"
class
=
"divGrid"
>
<
b
>Add New Role to Webpage Association</
b
>
<
br
/><
br
/>
<
table
>
<
tr
>
<
td
><
asp:Label
Text
=
"Web Page:"
runat
=
"server"
></
asp:Label
></
td
>
<
td
>
<
asp:DropDownList
ID
=
"ddlWebPages"
DataSourceID
=
'sqlDataSourceWebpages'
AppendDataBoundItems
=
"True"
DataTextField
=
"webpage_name"
DataValueField
=
"ID"
SelectedValue='<%# Bind("security_webpage_id") %>' runat="server">
<
asp:ListItem
Text
=
" "
Value
=
""
></
asp:ListItem
>
</
asp:DropDownList
>
</
td
>
</
tr
>
<
tr
>
<
td
><
br
/></
td
>
<
td
></
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label
Text
=
"Allow Add:"
runat
=
"server"
></
asp:Label
></
td
>
<
td
><
uc1:CheckBoxNullableChecked
ID
=
"chkboxAllowAdd"
Checked='<%# Bind("add_privledge") %>' runat="server" />
</
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label
Text
=
"Allow Edit:"
runat
=
"server"
></
asp:Label
></
td
>
<
td
><
uc1:CheckBoxNullableChecked
ID
=
"chkboxAllowEdit"
Checked='<%# Bind("edit_privledge") %>' runat="server" />
</
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label
Text
=
"Allow Delete:"
runat
=
"server"
></
asp:Label
></
td
>
<
td
><
uc1:CheckBoxNullableChecked
ID
=
"chkboxAllowDelete"
Checked='<%# Bind("delete_privledge") %>' runat="server" /></
td
>
</
tr
>
<
tr
>
<
td
><
asp:Button
ID
=
"btnUpdate"
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' runat="server" /></
td
>
<
td
><
asp:Button
ID
=
"btnCancel"
Text
=
"Cancel"
runat
=
"server"
CommandName
=
"Cancel"
CausesValidation
=
"false"
/></
td
>
</
tr
>
</
table
>
</
div
>
</
FormTemplate
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"rowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
</
div
>
<
asp:SqlDataSource
ID
=
"sqlDataSourceWebpages"
runat
=
"server"
SelectCommand
=
"SELECT * FROM dbo.security_webpage"
ConnectionString="<%$ ConnectionStrings:GATEConnectionString %>"></
asp:SqlDataSource
>
$create(Sys.Extended.UI.ModalPopupBehavior, {
"BackgroundCssClass"
:
"modalBackground"
,
"DropShadow"
:
true
,
"PopupControlID"
:
"Pnl_ForAdd"
,
"dynamicServicePath"
:
"/Main.aspx"
,
"id"
:
"MdlPppXtndr_Add_ID"
},
null
,
null
, $get(
"DummyForAdd"
));
<
system.web
>
​
...
​
<
httpHandlers
>
​
<
add
path
=
"Telerik.Web.UI.WebResource.axd"
type
=
"Telerik.Web.UI.WebResource"
verb
=
"*"
validate
=
"false"
/>
​
</
httpHandlers
>
​
...
​
</
system.web
>
​
<
system.webServer
>
​
...
​
<
handlers
>
​
<
add
name
=
"Telerik_Web_UI_WebResource_axd"
verb
=
"*"
preCondition
=
"integratedMode"
path
=
"Telerik.Web.UI.WebResource.axd"
type
=
"Telerik.Web.UI.WebResource"
/>
​
</
handlers
>
​
...
​
</
system.webServer
>
​
<
location
path
=
"Telerik.Web.UI.WebResource.axd"
>
​
<
system.web
>
​
<
authorization
>
​
<
allow
users
=
"*"
/>
​
</
authorization
>
​
</
system.web
>
​
</
location
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
EnablePageMethods
=
"True"
></
telerik:RadScriptManager
>
function
RowDataBound(sender, args) {
var
di = args.get_dataItem();
var
item = args.get_item();
var
sortUp = item.findElement(
'btnSortUp'
)
var
sortDown = item.findElement(
'btnSortDown'
)
//var sortUp = $(item).find("btnSortUp");
//var sortDown = $(item).find("btnSortDown");
var
pos = di.abdp_pos_no;
if
(pos == 1) {
$(sortDown).hide();
}
if
(pos == 4) {
$(sortUp).hide();
}
}
<
telerik:GridTemplateColumn
HeaderText
=
"Sort"
UniqueName
=
"sort"
SortExpression
=
"abdp_pos_no"
DataField
=
"ben"
>
<
HeaderStyle
HorizontalAlign
=
"Right"
/>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
<
ClientItemTemplate
>
<
img
id
=
"btnSortUp"
src
=
"images/copy.png"
data-pos
=
"#=abdp_pos_no #"
data-way
=
"-1"
style
=
"cursor:pointer;"
onclick
=
"reorder(this)"
></
img
>
<
img
id
=
"btnSortDown"
src
=
"images/copy.png"
data-pos
=
"#=abdp_pos_no #"
data-way
=
"+1"
style
=
"cursor:pointer;"
onclick
=
"reorder(this)"
></
img
>
</
ClientItemTemplate
>
</
telerik:GridTemplateColumn
>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"> |
</telerik:RadAjaxLoadingPanel> |
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="RadGridContactDetails"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGridContactDetails" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManagerProxy> |
<telerik:RadGrid AllowAutomaticInserts="true" AllowAutomaticDeletes="true" AllowAutomaticUpdates="true" ID="RadGridContactDetails" runat="server" skinId="kcResourceOpener" width="100%" height="245" Visible="true" DataSourceID="dsContactDetails"> |
<MasterTableView ShowHeadersWhenNoRecords="true" EditMode="EditForms" EnableNoRecordsTemplate="true" PageSize="10" CommandItemDisplay="Top" DataKeyNames="Priority"> |
<CommandItemTemplate> |
<table border="0" cellpadding="1" cellspacing="0" width="100%"> |
<tr> |
<td align="right"> |
<asp:LinkButton id="btnAddRecord" runat="server" ForeColor="#00247d" CssClass="Btn" CommandName="InitInsert" Text="Add"></asp:LinkButton> |
</td> |
</tr> |
</table> |
</CommandItemTemplate> |
<NoRecordsTemplate> |
No data available. |
</NoRecordsTemplate> |
<Columns> |
<telerik:GridTemplateColumn HeaderText="" AllowFiltering="false" ItemStyle-Wrap="false" HeaderStyle-Width="75pt"> |
<ItemTemplate> |
<asp:LinkButton ID="btnEdit" runat="server" Text="Select" ForeColor="#00247d" Font-Underline="false" CssClass="Btn" CommandName="Edit" Enabled="<%# not me.IsReadOnly %>" /> |
</ItemTemplate> |
<ItemStyle Wrap="False" /> |
</telerik:GridTemplateColumn> |
<telerik:GridButtonColumn ButtonType="PushButton" UniqueName="btnUp" ButtonCssClass="Btn" CommandName="MoveUp" Text="Up" HeaderText="" HeaderStyle-Width="15%"> |
</telerik:GridButtonColumn> |
<telerik:GridButtonColumn ButtonType="PushButton" UniqueName="btnDown" ButtonCssClass="Btn" CommandName="MoveDown" Text="Down" HeaderText="" HeaderStyle-Width="15%"> |
</telerik:GridButtonColumn> |
<telerik:GridDropDownColumn UniqueName="Type" DataField="Type" ListTextField="Type" ListValueField="Type" DataSourceID="dsContactDetailTypes" HeaderText="Type" HeaderStyle-Width="20%"> |
</telerik:GridDropDownColumn> |
<telerik:GridBoundColumn DataField="Detail" UniqueName="Detail" AllowFiltering="false" AllowSorting="false" HeaderText="Detail" HeaderStyle-Width="20%"> |
</telerik:GridBoundColumn> |
<telerik:GridButtonColumn ButtonType="PushButton" ButtonCssClass="Btn" CommandName="Delete" Text="Delete" HeaderText="" HeaderStyle-Width="15%"> |
</telerik:GridButtonColumn> |
</Columns> |
<EditFormSettings EditFormType="Template" CaptionFormatString="Enter/Edit the type and value for this detail record:"> |
<PopUpSettings Width="450px" /> |
<FormTemplate> |
<table width="100%" border="0" cellpadding="2" cellspacing="0"> |
<tr> |
<th align="left">Contact Details</th> |
<th colspan="2" align="right"> |
<asp:LinkButton ID="btnSaveDetail" CssClass="Btn" ForeColor="#00247d" Font-Underline="false" runat="server" CommandName='<%# IIf(TypeOf Container is GridEditFormInsertItem, "PerformInsert", "Update") %>' Text="Save" /> |
<asp:LinkButton ID="btnCancelDetail" CssClass="Btn" ForeColor="#00247d" Font-Underline="false" runat="server" CommandName="Cancel" Text="Cancel" /> |
</th> |
</tr> |
<tr> |
<td class="Form_Label" align="right">Type: </td> |
<td style="width:300px;" colspan="2"> |
<asp:DropDownList ID="dropDownDetailTypes" runat="server" DataSourceID="dsContactDetailTypes" DataTextField="Type" DataValueField="Type" Enabled='<%# not me.IsReadOnly %>'> |
</asp:DropDownList> |
</td> |
</tr> |
<tr> |
<td class="Form_Label">Detail: </td> |
<td> |
<asp:TextBox ID="txtDetailText" runat="server" Text='<%# Bind("Detail") %>' Enabled='<%# not me.IsReadOnly %>' Width="300px"></asp:TextBox> |
</td> |
<td> |
|
</td> |
</tr> |
<tr><td colspan="3"> </td></tr> |
</table> |
</FormTemplate> |
</EditFormSettings> |
</MasterTableView> |
</telerik:RadGrid> |
<asp:ObjectDataSource ID="dsContactDetails" runat="server" |
SelectMethod="Find" |
TypeName="SSI.KnowledgeCenter.ICKC.Resources.ContactDetailCollection" |
DataObjectTypeName="SSI.KnowledgeCenter.ICKC.Resources.ContactDetailCollection"> |
</asp:ObjectDataSource> |
<asp:XmlDataSource ID="dsContactDetailTypes" runat="server" DataFile="../App_Data/ContactDetailTypes.xml"> |
</asp:XmlDataSource> |
Private Sub RadGridContactDetails_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridContactDetails.ItemCommand |
Select Case e.CommandName |
Case RadGrid.InitInsertCommandName |
' Add button has been clicked: |
Case RadGrid.UpdateCommandName |
'e.Canceled = True |
'Dim newVals As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary() |
'newVals("Type") = Me.ContactDetails(e.Item.ItemIndex).Type |
'newVals("Detail") = Me.ContactDetails(e.Item.ItemIndex).Detail |
'e.Item.OwnerTableView.InsertItem(newVals) |
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) |
Dim d As IContactDetail = Me.ContactDetails(e.Item.ItemIndex) |
Dim dropDownDetailTypes As DropDownList = CType(editedItem.FindControl("dropDownDetailTypes"), DropDownList) |
If dropDownDetailTypes IsNot Nothing Then d.Type = dropDownDetailTypes.SelectedItem.Text |
Dim txtDetailText As TextBox = CType(editedItem.FindControl("txtDetailText"), TextBox) |
If txtDetailText IsNot Nothing Then d.Detail = txtDetailText.Text |
Case RadGrid.PerformInsertCommandName |
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) |
Dim d As New ContactDetail(_ConfigName, ICKCUser.ProviderUserKey) |
d.Priority = RadGridContactDetails.Items.Count + 1 |
Dim dropDownDetailTypes As DropDownList = CType(editedItem.FindControl("dropDownDetailTypes"), DropDownList) |
If dropDownDetailTypes IsNot Nothing Then d.Type = dropDownDetailTypes.SelectedItem.Text |
Dim txtDetailText As TextBox = CType(editedItem.FindControl("txtDetailText"), TextBox) |
If txtDetailText IsNot Nothing Then d.Detail = txtDetailText.Text |
Me.ContactDetails.Add(d) |
When I click the Save button on an Inserted Item, the DropDownList always shows the SelectedIndex = 0 instead of whatever selection is made. The TextBox control shows the Text property to be empty.
When I click the Save button on an Updated item, the DropDownList always shows the SelectedIndex to be whatever corresponds with the previous value of that property of the object. The TextBox control always shows the origjnal value for the associated property of the object.
I've also tried the Automatic EditForms and have also had no luck. In the InsertCommand event handler, I have tried two approaches:
Private Sub RadGridContactDetails_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridContactDetails.InsertCommand |
Dim newDetailItem As Telerik.Web.UI.GridEditableItem = CType(e.Item, Telerik.Web.UI.GridEditableItem) |
Dim newValues As Hashtable = New Hashtable() |
Dim detail As IContactDetail = New ContactDetail(_ConfigName, ICKCUser.ProviderUserKey) |
detail.Priority = RadGridContactDetails.Items.Count + 1 |
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, newDetailItem) |
Try |
For Each entry As DictionaryEntry In newValues |
Dim propertyName As String = entry.Key.ToString() |
Dim propertyValue As String = entry.Value |
Select Case propertyName |
Case "Type" |
detail.Type = propertyValue |
Case "Detail" |
detail.Detail = propertyValue |
Case Else |
Return |
End Select |
Me.ContactDetails.Add(detail) |
Next |
Catch ex As Exception |
_Manager.Alert(ex.Message) |
End Try |
End Sub |
and also this approach:
Private Sub RadGridContactDetails_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridContactDetails.InsertCommand |
Dim newItem As Telerik.Web.UI.GridEditableItem = CType(e.Item, Telerik.Web.UI.GridEditableItem) |
Dim editMan As Telerik.Web.UI.GridEditManager = newItem.EditManager |
Dim detail As IContactDetail = New ContactDetail(_ConfigName, ICKCUser.ProviderUserKey) |
detail.Priority = RadGridContactDetails.Items.Count + 1 |
For Each column As Telerik.Web.UI.GridColumn In e.Item.OwnerTableView.Columns |
If TypeOf column Is IGridEditableColumn Then |
Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn) |
If editableCol.IsEditable Then |
Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol) |
Dim editorText As String = "unknown" |
Dim editorValue As Object = Nothing |
If (TypeOf editor Is GridTextColumnEditor) Then |
editorText = CType(editor, GridTextBoxColumnEditor).Text |
editorValue = CType(editor, GridTextColumnEditor).Text |
End If |
If (TypeOf editor Is GridBoolColumnEditor) Then |
editorText = CType(editor, GridBoolColumnEditor).Value.ToString() |
editorValue = CType(editor, GridBoolColumnEditor).Value |
End If |
If (TypeOf editor Is GridDropDownColumnEditor) Then |
editorText = CType(editor, GridDropDownColumnEditor).SelectedText |
editorValue = CType(editor, GridDropDownColumnEditor).SelectedValue |
End If |
Select Case column.UniqueName |
Case "Type" |
detail.Type = editorText |
Case "Detail" |
detail.Detail = editorText |
Case Else |
Return |
End Select |
End If |
End If |
Next |
Me.ContactDetails.Add(detail) |
End Sub |
Neither approach has produced values from the EditForm for me. In both cases, I can get the name of the field, but not the value (in other words, I can find the column names but not the updated values).
I'm thinking this is an Ajax-related issue, but am unsure as to what is really going on here. I have placed a watch on the e.item object as it comes into the event handlers, but there are no values in the property reflecting the changes made on the EditForm. I see the controls, but not the associated values.
Any ideas would be very helpful at this point.
Thanks,
Charlie