Sorry it took me so long to get back to you. I was out of town for a week.
Here's the code behind to create the drop down as well as the events that correspond to it.
override protected void OnInit(EventArgs args)
{
Editor1.Initializing += new System.EventHandler(Editor1_Initializing);
Editor1.PostBackCommand += new System.Web.UI.WebControls.CommandEventHandler(Editor1_PostBackCommand);
Editor1.TextChanged += new System.EventHandler(Editor1_TextChanged);
base.OnInit(args);
}
private void Editor1_Initializing(object sender, EventArgs e)
{
loadDds();
}
protected void loadDds()
{
DropDownList templateDd = new DropDownList();
templateDd.ID = "fileDd";
templateDd.ToolTip = "Select Files";
templateDd.Font.Size = 10;
ListItem item = new ListItem();
item.Text = "Select Custom File";
item.Value = "0";
templateDd.Items.Add(item);
templateDd.AutoPostBack = true;
templateDd.CssClass = "CuteEditorDropDown";
SqlConnection conn = new SqlConnection(datasource);
conn.Open();
string sqlStr = "Select DISTINCT fileName, fileID from EmailApplicationSavedFiles where fileCreator='" + Session["emailApplicationUser"].ToString() + "' OR shareFile='1' OR shareFile='2' order by fileName";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
item = new ListItem();
item.Text = cleanData.b(reader["fileName"].ToString());
item.Value = reader["fileID"].ToString();
templateDd.Items.Add(item);
}
reader.Close();
conn.Close();
templateDd.SelectedIndexChanged += new EventHandler(templateDd_SelectedIndexChanged);
int position = Editor1.ToolControls.IndexOf("InsertDocument") + 1;
Editor1.InsertToolControl(position, "fileID", templateDd);
}
protected void templateDd_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;
string id = list.SelectedValue;
if (list.SelectedValue.Equals("0"))
{
Session["fileLoaded"] = 0;
Editor1.Text = "";
}
else
{
string save = "";
string creator = "";
SqlConnection conn = new SqlConnection(datasource);
conn.Open();
string sqlSTr = "Select fileText, shareFile, fileCreator from EmailApplicationSavedFiles where fileID='" + id + "'";
SqlCommand cmd = new SqlCommand(sqlSTr, conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
Editor1.Text = cleanData.b(reader["fileText"].ToString());
save = reader["shareFile"].ToString();
creator = reader["fileCreator"].ToString();
}
reader.Close();
conn.Close();
Session["fileLoaded"] = id;
//This if/else disables postback as described in the post
if (save.Equals("1") && !creator.Equals(Session["emailApplicationUser"].ToString()))
{
Editor1.DisableItemList = "Save";
Editor1.ToolTip = "You only have read access on this file. You cannot save changes made to it";
}
else
{
Editor1.DisableItemList = "";
}*/
}
}
protected void Editor1_PostBackCommand(object sender, CommandEventArgs e)
{
if (e.CommandName.Equals("Save"))
{
if (Session["fileLoaded"].ToString().Equals("0"))
{
saveFileMPE.Show();
fileSavedLbl.Visible = false;
saveFileBtn.Visible = true;
thisFileUpdatedLbl.Visible = false;
}
else
{
updateFileSave();
}
}
else
{
focusedControlID.Value = "CE_Editor1_ID";
thisFileUpdatedLbl.Visible = false;
}
}
protected void updateFileSave()
{
SqlConnection conn = new SqlConnection(datasource);
conn.Open();
SqlCommand cmd = new SqlCommand("EmailApplicationUpdateFile", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@fileID", Session["fileLoaded"].ToString());
cmd.Parameters.AddWithValue("@fileText", cleanData.Clean(Editor1.Text));
cmd.Parameters.AddWithValue("@lastSaveDate", System.DateTime.Now);
cmd.Parameters.AddWithValue("@lastSavedBy", Session["emailApplicationUser"].ToString());
cmd.ExecuteNonQuery();
conn.Close();
thisFileUpdatedLbl.Visible = true;
thisFileUpdatedLbl.Text = "File Saved";
}
protected void Editor1_TextChanged(object sender, EventArgs e)
{
focusedControlID.Value = "CE_Editor1_ID";
}
//Editor Declaration
<CE:Editor ID="Editor1" runat="server" AllowPasteHtml="true" OnPostBackCommand="Editor1_PostBackCommand"
OnTextChanged="Editor1_TextChanged" Height="700px" Width="950px" EditCompleteDocument="True"
EnableStripStyleTagsCodeInjection="False" EditorWysiwygModeCss="~/CuteSoft_Client/CuteEditor/Themes/Custom/style.css"
UsePhysicalFormattingTags="True">
</CE:Editor>