如何在asp.net中的DataGrid中创建iframe [英] How to create IFrames in DataGrid in asp.net

查看:120
本文介绍了如何在asp.net中的DataGrid中创建iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在创建一个类似站点的论坛,并且已经实现了一个(简单的)富文本区域.我能够在服务器上获取输入.但是我对如何从服务器上检索并呈现给用户一无所知.

Hello,

I am creating a forums like site and i have implemented a (simple) richtext area. I am able to fetch the input at server. But i dont have any idea on how to retrieve this from the server and present this to the user.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
        function def()
        {
            var testframe = document.createElement("iframe");
            testframe.name = testframe.id = "textEditor";
            testframe.width = 500;
            testframe.runat="server";

            if (testframe.addEventListener)
            {
                testframe.addEventListener("load",function(e){this.contentWindow.document.designMode = "on";}, false);
            }
            else if (testframe.attachEvent)
            {
                testframe.attachEvent("load", function(e){this.contentWindow.document.designMode = "on";});
            }

            frame.appendChild(testframe);

            textEditor.document.designMode="on";
            textEditor.document.open();
            textEditor.document.write('<head><style type="text/css">body{ font-family:arial; font-size:14px;}</style> </head><div id="txt"></div>');
            textEditor.document.close();
            textEditor.focus();
        }

        function fontEdit(x,y)
        {
            textEditor.document.execCommand(x,"",y);
            textEditor.focus();
        }
        function setHidden()
        {
            window.alert(textEditor.document.getElementById('txt').document.body.innerHTML);
            document.getElementById('cnt').value = textEditor.document.getElementById('txt').document.body.innerHTML;
            window.alert(document.getElementById('cnt').value);

        }

    </script>
</head>
<body onload="def()">
    <div id="frame"></div>
    <input type="button" id="btnBold" value="B" onclick="fontEdit('bold')" />
    <input type="button" id="btnItalics" value="I" onclick="fontEdit('italic')" />

    <form id="form1" runat="server">
        <input type="hidden" name="cnt" id="cnt"/>
        <asp:Button ID="btnSubmit" Text="submit" runat="server" OnClientClick="setHidden()" OnClick="btnSubmit_onClick" />
    </form>
</body>
</html>


如果有人能让我对此有所了解,那就太好了.我实际上希望Iframe成为数据网格的一部分,并且在绑定后我想将值分配给Iframe以显示内容.您在上面看到的代码适用于用户在其中输入注释的页面.但是帖子的内容将显示在datagrid中.
我忘了这就是我正在谈论的datagrid


It would be great if some one could give me an insight into this. I actually want Iframe to be part of datagrid and after binding i want to assign the value to the Iframe to display the contents.The code you see above is for the page where the user enters comments. But the contents of the post will be displayed in a datagrid.
Of i forgot this is the datagrid i am talking abt

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderStyle="Solid" ShowHeader="false" HeaderStyle-BorderStyle="None">
               <Columns>
                   <asp:TemplateField ShowHeader="false">

                       <ItemTemplate>
                           <table>
                               <tr>
                                   <td align="center">
                                       <asp:Label ID="lblCommentTitle" runat="server" ForeColor="Blue" Font-Italic="true" Text='<%# Bind("CommentTitle") %>'></asp:Label>
                                   </td>
                               </tr>
                               <tr>
                                   <td align="right">
                                       <asp:Label ID="lblCommentedBy" runat="server" ForeColor="Black" Text='<%# Bind("CommentedBy","Commented by {0}") %>'></asp:Label>
                                   </td>
                               </tr>
                               <tr>
                                   <td align="left">
                                       <asp:TextBox ID="txtCommentBody" runat="server" Width="493px" Height="196px" TextMode="MultiLine" ReadOnly="true"  Wrap="true" Text='<%# Bind("CommentBody") %>'></asp:TextBox>
                                   </td>
                               </tr>
                           </table>
                       </ItemTemplate>
                   </asp:TemplateField>


在这里,我想要一个iframe而不是TextBox.
请帮帮我.

在此先感谢.


Here instead of the TextBox, I want an iframe.
please help me.

Thanks in Advance.

推荐答案

您可以使用JavaScript通过create element
创建iframe元素吗? 您需要在某些事件或设计的最佳方式上调用js.
You could you use javascript to create iframe element using create element
you need to invoke the js on some events or your best way your design goes.


使用Javascript创建您的iframe.
Use Javascript to create your Iframe.


这篇关于如何在asp.net中的DataGrid中创建iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆