编辑数据库条目

发布于 2024-11-25 09:30:37 字数 334 浏览 1 评论 0原文

我正在使用 ASP.net 创建一个网站,如果您以管理员身份登录,您可以编辑当前页面的文本(这样我就不必为了一些小的更改而一直更新网站,我可以只需在其在线时自行编辑页面即可)。所有页面数据都存储在 SQL 数据库表中。每个条目只是“ID”和“PAGECONTENT”。现在,我使用 SQLDataSource 来获取数据并将其放入页面上的 FormView 中。这一切都有效。我制作了一个按钮,仅当我以站点管理员身​​份登录时才可见。我需要做到这一点,以便当我单击按钮时,显示页面内容的文本标签变成一个 TextArea 供我编辑,然后我可以单击“完成”按钮并将其更新到数据库表。我可以完成更新部分,我只是不知道应该如何以可编辑的方式显示文本......

I'm creating a website with ASP.net that, if you are logged in as an admin, you can edit the current pages text (this way I don't have to update the website all the time just for small changes, I can just edit the page myself while its online). All the page data is stored in a SQL Database table. Each entry is simply "ID" and "PAGECONTENT". Now, I used a SQLDataSource to get the data and put it into a FormView on my page. This all works. I made a button that is only visible if I'm logged in as the site-admin. I need to make it so when I click the button, the textlabel displaying the page content turns into a TextArea for me to edit, then I can click a "Done" button and have it update it to the Database table. I can do the updating part, I just don't know how I'm supposed to display the text in an editable manner...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与往事干杯 2024-12-02 09:30:37

您需要一种称为富文本编辑器控件的东西。这将为您提供一个带有工具栏等的 Microsoft Word 风格界面,并且它将为您解析存储在数据库中的 html。

那里有很多免费的。常用的一个是 Ajax Control Toolkit 中包含的一个。

您应该使用 nuget 将最新的 Ajax Control Toolkit 安装到您的项目中。

有很多教程解释了如何使用此控件:

You need something called a Rich Text Editor control. This will give you a Microsoft Word style interface with a toolbar etc and it will parse the html for you that you have stored in the database.

There are lots of free ones out there. A commonly used one is the one included in the Ajax Control Toolkit.

You should use nuget to install the latest Ajax Control Toolkit into your project.

There are lots of tutorials out there which explain how to use this control:

云裳 2024-12-02 09:30:37

POST 场景:就像您有一个仅在您以站点管理员身​​份登录时可见的按钮一样,有一个文本区域仅在您单击编辑按钮时可见,并在您单击完成按钮时保存它。

一个好的做法是为数据库条目的版本提供一个专用页面,除非您使用的是 ajax 界面。从详细视图更改为编辑视图时进行 POST 以及在保存时再次进行 POST 可能会变得复杂且不安全。这只是一个想法。

GET-then-POST 场景:为您的数据库条目提供一个专用的编辑页面。比方说:/editpage.aspx?id=1。该页面上有一个完成按钮,用于回发并保存您的工作。

祝你好运。

The POST scenario: Just like you have a button that is visible only when you're logged as the site admin, have a textarea only visible when you click the edit button and have it saved when you click the done button.

A good practice would be to have a dedicated page for the edition of your db entry unless you're working with an ajax interface. It can get complicated and unsafe to POST when changing from a detail view to an edit view and to POST again when saving. That's just an idea.

The GET-then-POST scenario: have a dedicated edit page for your db entry. Let's say: /editpage.aspx?id=1. Have a done button on that page that postback and save your work.

Good luck.

等待圉鍢 2024-12-02 09:30:37

http://www.w3schools.com/aspnet/control_htmltextarea.asp

也许这就是什么你正在寻找。

    <script  runat="server">
Sub submit(sender As Object, e As EventArgs)
   p1.InnerHtml = "<b>You wrote:</b> " & textarea1.Value
End Sub
</script>

<html>
<body>

<form runat="server">
Enter some text:<br />
<textarea id="textarea1" cols="35" rows="6" runat="server" value="PUT_YOUR_TEXT_HERE_to_prepopulate_the_Data" />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>

</body>
</html>

http://www.w3schools.com/aspnet/control_htmltextarea.asp

maybe this is what you are looking for.

    <script  runat="server">
Sub submit(sender As Object, e As EventArgs)
   p1.InnerHtml = "<b>You wrote:</b> " & textarea1.Value
End Sub
</script>

<html>
<body>

<form runat="server">
Enter some text:<br />
<textarea id="textarea1" cols="35" rows="6" runat="server" value="PUT_YOUR_TEXT_HERE_to_prepopulate_the_Data" />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>

</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文