编辑数据库条目
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要一种称为富文本编辑器控件的东西。这将为您提供一个带有工具栏等的 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:
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.
http://www.w3schools.com/aspnet/control_htmltextarea.asp
也许这就是什么你正在寻找。
http://www.w3schools.com/aspnet/control_htmltextarea.asp
maybe this is what you are looking for.