设置,获取editor中的值:
设置 function InsertSpecialSymbol(symbol) {
var selection = HtmlEditor.GetSelection();
selection.SetHtml(symbol);
获取:
The ASPxHtmlEditor's content can be specified and obtained, using the following methods and properties:
|
||||
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server" ClientInstanceName="htmlEditor"> </dx:ASPxHtmlEditor> <br/> <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="ASPxButton"> <ClientSideEvents Click="function(s, e) { var myText = htmlEditor.GetHtml(); myMemo.SetText(myText); }" /> </dx:ASPxButton> <br/> <dx:ASPxMemo ID="ASPxMemo1" runat="server" ClientInstanceName="myMemo" Height="71px" Width="170px"> </dx:ASPxMemo> |
Asp |
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server" ClientInstanceName="htmlEditor"> </dx:ASPxHtmlEditor> <br/> <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="ASPxButton"> <ClientSideEvents Click="function(s, e) { var myText = htmlEditor.GetHtml(); myMemo.SetText(myText); }" /> </dx:ASPxButton> <br/> <dx:ASPxMemo ID="ASPxMemo1" runat="server" ClientInstanceName="myMemo" Height="71px" Width="170px"> </dx:ASPxMemo> |
The ASPxClientHtmlEditor.SetHtml client method is used to specify an HTML markup that represents the editor's content.
|
||||
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server" ClientInstanceName="htmlEditor"> </dx:ASPxHtmlEditor> <br/> <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="ASPxButton"> <ClientSideEvents Click="function(s, e) { htmlEditor.SetHtml('Sample Text'); }" /> </dx:ASPxButton> |
Asp |
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server" ClientInstanceName="htmlEditor"> </dx:ASPxHtmlEditor> <br/> <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="ASPxButton"> <ClientSideEvents Click="function(s, e) { htmlEditor.SetHtml('Sample Text'); }" /> </dx:ASPxButton> |
The ASPxHtmlEditor.Html property specifies the HTML markup representing the ASPxHtmlEditor's content.
|
||||
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server" ClientInstanceName="htmlEditor" Html="<STRONG>Sample Text</STRONG>" > </dx:ASPxHtmlEditor> |
Save To file:
Aspx:
<div id="Div1">Your name:</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div id="Div2">Your message:</div>
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server">
</dx:ASPxHtmlEditor>
<asp:Button ID="Button1" runat="server" Text="Save to File" onclick="Button1_Click" />
C#:
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
string myHtml = ASPxHtmlEditor1.Html.ToString();
string fileName = TextBox1.Text + DateTime.Today.Date.ToShortDateString() + ".txt";
string fullFileName = Request.MapPath("Files/" + fileName);
StreamWriter streamWriter =
new StreamWriter(new FileStream(fullFileName, FileMode.Create, FileAccess.Write));
streamWriter.Write(myHtml);
streamWriter.Close();
}
}
保存到数据库:
The ASPxHtmlEditor'a content can be saved as an HTML markup to a database the following ways:
The following example illustrates the data-bound ASPxHtmlEditor within the ASPxGridView. After editing, the updated ASPxGridView content is saved to the database.
Aspx:<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Data_28072008.mdb"
SelectCommand="SELECT * FROM [Table1]"
DeleteCommand="DELETE FROM [Table1] WHERE [ID] = ?"
InsertCommand="INSERT INTO [Table1] ([ID], [Name], [DescriptionHtml]) VALUES (?, ?, ?)"
UpdateCommand="UPDATE [Table1] SET [Name] = ?, [DescriptionHtml] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="DescriptionHtml" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="DescriptionHtml" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
Width="369px" DataSourceID="AccessDataSource1" KeyFieldName="ID">
<Templates>
<EditForm>
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor2" runat="server"
Html='<%# Bind("DescriptionHtml") %>'>
</dx:ASPxHtmlEditor>
<br/>
<div style="text-align: right; padding: 2px 2px 2px 2px">
<dxwgv:ASPxGridViewTemplateReplacement ID="UpdateButton"
ReplacementType="EditFormUpdateButton" runat="server">
</dxwgv:ASPxGridViewTemplateReplacement>
<dxwgv:ASPxGridViewTemplateReplacement ID="CancelButton"
ReplacementType="EditFormCancelButton" runat="server">
</dxwgv:ASPxGridViewTemplateReplacement>
</div>
</EditForm>
</Templates>
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataTextColumn FieldName="ID" ReadOnly="True"
VisibleIndex="1">
<EditFormSettings Visible="False" />
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="Name" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="DescriptionHtml" VisibleIndex="3">
<PropertiesTextEdit EncodeHtml="False">
</PropertiesTextEdit>
</dxwgv:GridViewDataTextColumn>
</Columns>
</dxwgv:ASPxGridView>
In the following example, the Save To DataBase button creates a connection with the Access DataBase and inserts the ASPxHtmlEditor's contents into a new tuple.
Aspx: <div id="Div1">Your name:</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div id="Div2">Your message:</div>
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server">
</dx:ASPxHtmlEditor>
<asp:Button ID="Button1" runat="server" Text="Save to DataBase" onclick="Button1_Click" />
C#:public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
string MyHtml = ASPxHtmlEditor1.Html.ToString();
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:/Solutions/MyProject/App_Data/test.mdb";
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "INSERT INTO Table1(Name,DescriptionHtml)
VALUES (@name,@message)";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = myCommand;
dataAdapter.SelectCommand.Parameters.Add("@name",
OleDbType.VarChar, 50).Value = TextBox1.Text;
dataAdapter.SelectCommand.Parameters.Add("@message",
OleDbType.VarChar, 200).Value = ASPxHtmlEditor1.Html.ToString();
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "Table1");
myConnection.Close();
}
}