asp.net - 使用 VB.NET 在 ASP.NET 中的 detailsView 中集成 CKEditor

标签 asp.net database ado.net ckeditor ckeditor.net

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

<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>

我想使用 CKEditor 在详细 View 中编辑数据,以插入和删除与数据库的链接。以前有人这样做过吗?

最佳答案

我不是 DetailsView 专家,但我认为以下一般性摘要涵盖了您需要执行的操作。

为 Station_Name 使用 TemplateField 而不是 BoundField。看起来像这样:

 <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>

This看起来像是一个关于从 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

如果事实证明您无法绑定(bind)到 CKEditor 控件的 Text 属性,您可以将该值分配给 CKEditorText 控件以与检索它相同的方式:通过执行 DetailsViewStation.FindControl("CKEditor1") 来检索控件,并将从数据库检索到的 HTML 分配给控件的 文本 属性。

希望对您有所帮助。

关于asp.net - 使用 VB.NET 在 ASP.NET 中的 detailsView 中集成 CKEditor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14024373/

相关文章:

c# - 在 asp.net mvc 中,下拉列表值始终返回零

mysql - 为什么在我们已经从内部 SELECT 中找到数据后调用 JOIN?

database - SQL Server CE 数据库和 ADO.Net Entity Framework - 数据未保存

c# - 以编程方式创建 SQL 数据库

php - Eloquent 地删除多对多行

ado.net - 缺少 DbProviderFactories.GetFactory 方法 (DbConnection)

asp.net - 如何通过 Azure Active Directory 对 Multi-Tenancy ASP.NET 应用程序进行身份验证?

javascript - 如何以编程方式将图片上传到 Facebook?

asp.net - Visual Studio 2015 IIS Express 500 错误

mysql - SQL 选择重叠行