After hours of research, I have figured out my own solution to some issues I reported earlier. So to summarize all my issues and solutions:
I experienced two major BINDING issues with fields under <EditFormSettings EditFormType="Template"><FormTemplate>:
1. DropDownList - Setting the SelectedValue property to <%# Bind("security_webpage_id") %> caused an error when clicking on the Add New Record button. The error was 'ddlWebPages' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value.
Fix: I added a blank listitem. My Dropdown tag looked like this after fix:
<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>
2. Checkbox - I had three checkboxes that received an error when I clicked on the Add New Record button.
The error was "Specified cast is not valid".
Fix: I created a User Control for the CheckBox and handled the passing of null value to the Checked property which is what was happening when the Add New Record button was clicked. Below is my code for the code behind and markup of the checkbox control.
Code-Behind:
Mark-up:
Registering User Control in markup file that contains the standard Checkbox;
Your Checkbox and/or Drop Down List will look like this now under the FormTemplate:
Hopefully this will help someone else not have to go through days of pain that I did over there two issues
I experienced two major BINDING issues with fields under <EditFormSettings EditFormType="Template"><FormTemplate>:
1. DropDownList - Setting the SelectedValue property to <%# Bind("security_webpage_id") %> caused an error when clicking on the Add New Record button. The error was 'ddlWebPages' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value.
Fix: I added a blank listitem. My Dropdown tag looked like this after fix:
<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>
2. Checkbox - I had three checkboxes that received an error when I clicked on the Add New Record button.
The error was "Specified cast is not valid".
Fix: I created a User Control for the CheckBox and handled the passing of null value to the Checked property which is what was happening when the Add New Record button was clicked. Below is my code for the code behind and markup of the checkbox control.
Code-Behind:
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;
}
}
}
Mark-up:
%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CheckBoxNullableChecked.ascx.cs" Inherits="FRC.CheckBoxNullableChecked" %>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
/>
Registering User Control in markup file that contains the standard Checkbox;
<%@ Register src="~/CheckBoxNullableChecked.ascx" TagName="CheckBoxNullableChecked"
TagPrefix="uc1" %>
Your Checkbox and/or Drop Down List will look like this now under the FormTemplate:
<
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
>
Hopefully this will help someone else not have to go through days of pain that I did over there two issues