Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从aspx.cs文件复制aspx列表视图?_C#_Asp.net_.net - Fatal编程技术网

C# 如何从aspx.cs文件复制aspx列表视图?

C# 如何从aspx.cs文件复制aspx列表视图?,c#,asp.net,.net,C#,Asp.net,.net,如何从aspx.cs文件复制.aspx ListView(包括其LayoutTemplate和ItemTemplate)?.aspx.cs使用DataBind()将值显示在页面上 所以我想从本质上说: <asp:ListView ID="EvalAnswerList" OnItemDataBound="EvalAnswerList_ItemDataBound" runat="server"> <LayoutTemplate>

如何从aspx.cs文件复制.aspx ListView(包括其LayoutTemplate和ItemTemplate)?.aspx.cs使用DataBind()将值显示在页面上

所以我想从本质上说:

<asp:ListView ID="EvalAnswerList" OnItemDataBound="EvalAnswerList_ItemDataBound" runat="server">
            <LayoutTemplate>
                <table cellpadding="2" width="640px" border="1" runat="server" class="altRows" id="tblProducts">
                    <tr id="Tr1" runat="server">
                        <th id="Th1" runat="server">Question
                        </th>
                    </tr>
                    <tr runat="server" id="itemPlaceholder" />
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr id="Tr2" runat="server">
                    <td>
                        <asp:Label ID="QuestionTextLabel" Font-Bold="true" runat="server" />
                    </td>
                </tr>
            </ItemTemplate>
</asp:ListView>

然后尝试在test.DataBind()中使用它,但它不起作用。

您可以使用webusercontrol,请尝试以下步骤

步骤1:创建一个usercontrol并将列表视图放在其中

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomListView.ascx.cs"
    Inherits="CustomListView" %>
<asp:ListView ID="EvalAnswerList" OnItemDataBound="EvalAnswerList_ItemDataBound"
    runat="server">
    <layouttemplate>
                <table cellpadding="2" width="640px" border="1" runat="server" class="altRows" id="tblProducts">
                    <tr id="Tr1" runat="server">
                        <th id="Th1" runat="server">Question
                        </th>
                    </tr>
                    <tr runat="server" id="itemPlaceholder" />
                </table>
            </layouttemplate>
    <itemtemplate>
                <tr id="Tr2" runat="server">
                    <td>
                        <asp:Label ID="QuestionTextLabel" Font-Bold="true" runat="server" />
                    </td>
                </tr>
            </itemtemplate>
</asp:ListView>
enter code here
步骤3:现在在aspx页面中添加对usercontrol的引用

<%@ Reference Control="CustomListView.ascx" %>
enter code here

祝你好运

您可以使用webusercontrol,请尝试以下步骤

步骤1:创建一个usercontrol并将列表视图放在其中

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomListView.ascx.cs"
    Inherits="CustomListView" %>
<asp:ListView ID="EvalAnswerList" OnItemDataBound="EvalAnswerList_ItemDataBound"
    runat="server">
    <layouttemplate>
                <table cellpadding="2" width="640px" border="1" runat="server" class="altRows" id="tblProducts">
                    <tr id="Tr1" runat="server">
                        <th id="Th1" runat="server">Question
                        </th>
                    </tr>
                    <tr runat="server" id="itemPlaceholder" />
                </table>
            </layouttemplate>
    <itemtemplate>
                <tr id="Tr2" runat="server">
                    <td>
                        <asp:Label ID="QuestionTextLabel" Font-Bold="true" runat="server" />
                    </td>
                </tr>
            </itemtemplate>
</asp:ListView>
enter code here
步骤3:现在在aspx页面中添加对usercontrol的引用

<%@ Reference Control="CustomListView.ascx" %>
enter code here

祝你好运

最后,我使用了一个中继器控件,它成功了。谢谢

最后,我使用了一个中继器控件,它成功了。谢谢

使用中继器控件怎么样?使用中继器控件怎么样?
<%@ Reference Control="CustomListView.ascx" %>
enter code here
CustomListView clv = new CustomListView();
clv.dsSource = ds;//dataset/datatable to bind listview
div.Controls.Add(clv);