使用VB.NET将CKEditor集成到ASP.NET的detailsView中

Ahm*_*med 6 database asp.net ado.net ckeditor ckeditor.net

我正在尝试将CKEditor与详细信息视图集成.我的示例代码是:

<asp:DetailsView ID="DetailsViewStation" runat="server" Height="50px" AutoGenerateRows="False"
                    DataKeyNames="StationNo" DataSourceID="StationSqlDataSource" CellPadding="4"
                    ForeColor="#333333" GridLines="None">
                    <AlternatingRowStyle BackColor="White" />
                    <CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
                    <FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
                    <Fields>
                        <asp:BoundField DataField="StationNo" HeaderText="Station Number" ReadOnly="True"
                            SortExpression="StationNo" ApplyFormatInEditMode="True">
                            <HeaderStyle Width="150px" />
                            <ItemStyle HorizontalAlign="Center" Width="1200px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Station_Name" HeaderText="Station Name" SortExpression="Station_Name">
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                    </Fields>
                    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                </asp:DetailsView>
                <asp:SqlDataSource ID="StationSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AgainConnectionString %>"
                    DeleteCommand="DELETE FROM [StationInfoTable] WHERE [StationNo] = @StationNo"
                    InsertCommand="INSERT INTO [StationInfoTable] ([StationNo], [Station_Name] VALUES (@StationNo, @Station_Name)"
                    SelectCommand="SELECT * FROM [StationInfoTable] WHERE ([StationNo] = @StationNo)"
                    UpdateCommand="UPDATE [StationInfoTable] SET [Station_Name] = @Station_Name, [Importatnat_Info] = @Importatnat_Info WHERE [StationNo] = @StationNo">
                    <DeleteParameters>
                        <asp:Parameter Name="StationNo" Type="Int32" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="StationNo" Type="Int32" />
                        <asp:Parameter Name="Station_Name" Type="String" />
                    </InsertParameters>
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ListBoxChoices" Name="StationNo" PropertyName="SelectedValue"
                            Type="Int32" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Station_Name" Type="String" />
                        <asp:Parameter Name="StationNo" Type="Int32" />
                    </UpdateParameters>
                </asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud)

我想使用CKEditor在详细信息视图中编辑数据,以插入和删除与数据库之间的链接.以前有人这么做过吗?

Ann*_* L. 5

我不是DetailsView专家,但我认为以下总摘要涵盖了您需要做的事情.

使用TemplateField而不是BoundField用于Station_Name.这看起来像这样:

 <asp:TemplateField HeaderText="Station Name">
     <ItemTemplate>
          <asp:Label ID="lblStationName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Station_Name") %>'></asp:Label>
     </ItemTemplate>
     <EditItemTemplate>
          <CKEditor:CKEditorControl ID="CKEditor1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Station_Name") %>' />
     </EditItemTemplate>
</asp:TemplateField>
Run Code Online (Sandbox Code Playgroud)

似乎是从a更新数据库的良好链接DetailsView.你的情况与他的不同之处在于你正在使用CKEditor.但是CKEditor,当他准备更新时,您可以像控制一样检索控件中的信息:

Dim htmlText as String = Nothing
Dim ctl as CKEditor =  CType(DetailsViewStation.FindControl("CKEditor1"), CKEditor)
If ctl Is Nothing Then
    htmlText = ctl.Text
End If
Run Code Online (Sandbox Code Playgroud)

如果事实证明您无法绑定到CKEditor控件的Text属性,则将值赋值给CKEditor.Text控制与检索它的方式相同:通过执行a DetailsViewStation.FindControl("CKEditor1")检索控件,并将从数据库中检索到的HTML分配给控件的Text属性.

我希望这有帮助.