我的列表视图中有错误

时间:2013-08-01 03:52:12

标签: c# asp.net

这是问题所在:

编译错误

描述:编译服务此请求所需的资源时发生错误。请查看以下特定错误详细信息并相应地修改源代码。

编译器错误消息:CS0118:' System.Web.UI.WebControls.SqlDataSource'是一种'类型'但用作变量'

来源错误:

第31行:
第32行:
第33行:" RUNAT ="服务器" 第35行:DataSourceID =" SqlDataSource1"

这是我的代码:

    <asp:ListView ID="ListView1" GroupItemCount="3" DataKeyNames="pic_id"
        DataSource="<%# SqlDataSource %>" runat="server" 
        DataSourceID="SqlDataSource1" 
        onselectedindexchanged="ListView1_SelectedIndexChanged">
        <AlternatingItemTemplate>
            <td runat="server" style="background-color: #FFFFFF;color: #284775;">
                pic_id:
                <asp:Label ID="pic_idLabel" runat="server" Text='<%# Eval("pic_id") %>' />
                <br />
                picture_tag:
                <asp:Label ID="picture_tagLabel" runat="server" 
                    Text='<%# Eval("picture_tag") %>' />
                <br />
                pic:
                <asp:Label ID="picLabel" runat="server" Text='<%# Eval("pic") %>' />
                <br />
            </td>
        </AlternatingItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" 
                style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <td runat="server" style="">
                picture_tag:
                <asp:TextBox ID="picture_tagTextBox" runat="server" 
                    Text='<%# Bind("picture_tag") %>' />
                <br />
                pic:
                <asp:TextBox ID="picTextBox" runat="server" Text='<%# Bind("pic") %>' />
                <br />
                <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                    Text="Insert" />
                <br />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                    Text="Clear" />
                <br />
            </td>
        </InsertItemTemplate>
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table ID="groupPlaceholderContainer" runat="server" border="1" 
                            style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                            <tr ID="groupPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" 
                        style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
                        <asp:DataPager ID="DataPager1" runat="server" PageSize="12">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <EditItemTemplate>
            <td runat="server" style="background-color: #999999;">
                pic_id:
                <asp:Label ID="pic_idLabel1" runat="server" Text='<%# Eval("pic_id") %>' />
                <br />
                picture_tag:
                <asp:TextBox ID="picture_tagTextBox" runat="server" 
                    Text='<%# Bind("picture_tag") %>' />
                <br />
                pic:
                <asp:TextBox ID="picTextBox" runat="server" Text='<%# Bind("pic") %>' />
                <br />
                <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                    Text="Update" />
                <br />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                    Text="Cancel" />
                <br />
            </td>
        </EditItemTemplate>
        <GroupTemplate>
            <tr ID="itemPlaceholderContainer" runat="server">
                <td ID="itemPlaceholder" runat="server">
                </td>
            </tr>
        </GroupTemplate>
        <EmptyItemTemplate>
            <td runat="server" />
            </EmptyItemTemplate>
        <ItemTemplate>
            <td runat="server" style="background-color: #E0FFFF;color: #333333;">
                pic_id:
                <asp:Label ID="pic_idLabel" runat="server" Text='<%# Eval("pic_id") %>' />
                <br />
                picture_tag:
                <asp:Label ID="picture_tagLabel" runat="server" 
                    Text='<%# Eval("picture_tag") %>' />
                <br />
                pic:
                <asp:Label ID="picLabel" runat="server" Text='<%# Eval("pic") %>' />
                <br />
            </td>
        </ItemTemplate>
            <SelectedItemTemplate>
                <td runat="server" 
                    style="background-color: #E2DED6;font-weight: bold;color: #333333;">
                    pic_id:
                    <asp:Label ID="pic_idLabel" runat="server" Text='<%# Eval("pic_id") %>' />
                    <br />
                    picture_tag:
                    <asp:Label ID="picture_tagLabel" runat="server" 
                        Text='<%# Eval("picture_tag") %>' />
                    <br />
                    pic:
                    <asp:Label ID="picLabel" runat="server" Text='<%# Eval("pic") %>' />
                    <br />
                </td>
            </SelectedItemTemplate>
        </asp:ListView>

2 个答案:

答案 0 :(得分:0)

删除DataSource="<%# SqlDataSource %>"

来自ListView定义

答案 1 :(得分:0)

如果您从后端绑定listview,则无法在正面大小上添加数据源...