Hi,
I have the below code which runs fine until I click on Edit, then I get:
Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null.
Parameter name: elements
Any idea why I am getting the JScript or work around?
Thank you!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="display:None">
<cc1:Editor ID="Editor1" runat="server" />
</div>
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:GridView ID="list" runat="server" DataKeyNames="ID" AutoGenerateColumns="False"
Width="600px" Height="350px" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" CellPadding="3" OnRowDeleting="list_RowDeleting" OnRowUpdating="list_RowUpdating"
OnRowCancelingEdit="list_RowCancelingEdit"
OnRowEditing="list_RowEditing"
onselectedindexchanged="list_SelectedIndexChanged">
<RowStyle ForeColor="#000066" />
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<%# Eval("ID") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Created">
<ItemTemplate>
<%# Eval("Edited_By")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments">
<EditItemTemplate>
<cc1:Editor ID="editor1" runat="server" Width="500px" Height="250px"/>
</EditItemTemplate>
<ItemTemplate>
<%# Eval("Manager") %>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:ButtonField CommandName="Delete" Text="Delete" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AjaxControlToolkit;
public partial class _Default : System.Web.UI.Page
{
private string cnstr = ConfigurationManager.ConnectionStrings["Database1ConnectionST"].ConnectionString;
private string sql;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillGridview1();
AjaxControlToolkit.HTMLEditor.Editor edit = new AjaxControlToolkit.HTMLEditor.Editor();
//edit = (AjaxControlToolkit.HTMLEditor.Editor)row.FindControl("Editor1") as AjaxControlToolkit.HTMLEditor.Editor;
}
}
public DataTable FetchTypeEditedBy()
{
string sql = "Select ID, Edited_By, Manager From mydb";
SqlDataAdapter da = new SqlDataAdapter(sql, cnstr);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
private void FillGridview1()
{
DataTable dtProjects = FetchTypeEditedBy();
if (dtProjects.Rows.Count > 0)
{
list.DataSource = dtProjects;
list.DataBind();
}
else
{
dtProjects.Rows.Add(dtProjects.NewRow());
list.DataSource = dtProjects;
list.DataBind();
int TotalColumns = list.Rows[0].Cells.Count;
list.Rows[0].Cells.Clear();
list.Rows[0].Cells.Add(new TableCell());
list.Rows[0].Cells[0].ColumnSpan = TotalColumns;
list.Rows[0].Cells[0].Text = "No Record Found";
}
}
protected void list_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//retrive the updated data
string Id = list.DataKeys[e.RowIndex].Value.ToString();
int index = list.EditIndex;
GridViewRow row = list.Rows[index];
AjaxControlToolkit.HTMLEditor.Editor edit = (AjaxControlToolkit.HTMLEditor.Editor)row.FindControl("Editor1") as AjaxControlToolkit.HTMLEditor.Editor;
string EditorContent = edit.Content;
//Execute the update stored procedure
//bool success = ReviewAccess.EditReview(reviewId, review);
// Cancel edit mode
list.EditIndex = -1;
//Display status message
Label1.Text ="Update successful Update failed";
//Reload the grid
// BindGrid();
}
protected void list_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
}
protected void list_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
protected void list_RowEditing(object sender, GridViewEditEventArgs e)
{
list.EditIndex = e.NewEditIndex;
FillGridview1();
}
protected void list_SelectedIndexChanged(object sender, EventArgs e)
{
}
}