ASP.NET转发器未在浏览器中呈现

时间:2019-04-27 17:25:25

标签: asp.net vb.net

在设计视图中,我可以看到转发器,但是在浏览器中,转发器根本没有显示。

创建了一个转发器,无法渲染它。当我们检查对象时,它不会出现。我使用了上面的代码,称为分析注册数据并在转发器之后重复,看不到,但是转发器没有。有什么问题吗?下面的代码来自分析注册数据:     

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">


        <table>
<tr>
<td>
    <asp:GridView ID="GridView1" ShowHeader="false" 
        GridLines="None" AutoGenerateColumns="false"
        runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <table style="border: 1px solid #A55129; 
                        background-color: #FFF7E7">
                        <tr>
                            <td style="width: 200px">
                                <asp:Image ID="imgEmployee" 
                                    ImageUrl='<%# Eval("PhotoPath")%>' 
                                    runat="server" />
                            </td>
                            <td style="width: 200px">
                                <table>
                                    <tr>
                                        <td>
                                            <b>Id:</b>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblId" 
                                            runat="server" 
                                            Text='<%#Eval("EmployeeId") %>'>
                                            </asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <b>Name:</b>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblName" 
                                            runat="server" 
                                            Text='<%#Eval("Name") %>'>
                                            </asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <b>Gender:</b>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblGender" 
                                            runat="server" 
                                            Text='<%#Eval("Gender") %>'>
                                            </asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <b>City:</b>
                                        </td>
                                        <td>
                                            <asp:Label ID="lblCity" 
                                            runat="server" 
                                            Text='<%#Eval("City") %>'>
                                            </asp:Label>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
</td>
<td>
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <table style="border: 1px solid #A55129; 
                background-color: #FFF7E7">
                <tr>
                    <td style="width: 200px">
                        <asp:Image ID="imgEmployee" 
                        ImageUrl='<%# Eval("PhotoPath")%>' 
                        runat="server" />
                    </td>
                    <td style="width: 200px">
                        <table>
                            <tr>
                                <td>
                                    <b>Id:</b>
                                </td>
                                <td>
                                    <asp:Label ID="lblId" 
                                    runat="server" 
                                    Text='<%#Eval("EmployeeId") %>'>
                                    </asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Name:</b>
                                </td>
                                <td>
                                    <asp:Label ID="lblName" 
                                    runat="server" 
                                    Text='<%#Eval("Name") %>'>
                                    </asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>Gender:</b>
                                </td>
                                <td>
                                    <asp:Label ID="lblGender" 
                                    runat="server" 
                                    Text='<%#Eval("Gender") %>'>
                                    </asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <b>City:</b>
                                </td>
                                <td>
                                    <asp:Label ID="lblCity" 
                                    runat="server" 
                                    Text='<%#Eval("City") %>'>
                                    </asp:Label>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
        <SeparatorTemplate>
            <asp:Image ID="Image1" 
            ImageUrl="~/Images/1x1PixelImage.png" 
            runat="server" />
        </SeparatorTemplate>
    </asp:Repeater>
</td>
</tr>
</table>
        <div>
        </div>
    </form>
</body>
</html>
//////////////////


Imports System.Data.SqlClient

Public Class WebForm2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim con As SqlConnection = New SqlConnection("data source=.; database=image; integrated security=SSPI")
        Dim cmd As SqlCommand = New SqlCommand("Select * from tblEmployee", con)
        con.Open()
        Dim rdr As SqlDataReader = cmd.ExecuteReader()
        GridView1.DataSource = rdr
        GridView1.DataBind()
        Repeater1.DataSource = rdr

2 个答案:

答案 0 :(得分:0)

您的中继器需要一个数据源,然后您需要致电DataBind。

Repeater1.DataSource = rdr
Repeater1.DataBind()

我建议您也将其包装在Not IsPostBack有条件的

if Not IsPostback
   Repeater1.DataSource = rdr
   Repeater1.DataBind()

答案 1 :(得分:0)

GridView1.DataSource = rdr
GridView1.DataBind()
Repeater1.DataSource = rdr
Repeater1.DataBind()