母版页中内容页的GridView问题
我在母版页所属内容页中添加了一个SqlDataSource控件和一个GridView控件,设置好运行的时候报错【类型“GridView”的控件“ctl00_Content...
我在母版页所属内容页中添加了一个SqlDataSource控件和一个GridView控件,设置好运行的时候报错【类型“GridView”的控件“ctl00_ContentPlaceHolder1_GridView1”必须放在具有 runat=server 的窗体标记内。 】。可是我Contact和GridView控件都写有runat=server,不知道怎么回事?
源代码<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="abc.aspx.cs" Inherits="_Default" Title="abc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="id" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xiaolu %>"
DeleteCommand="DELETE FROM [otherplace] WHERE [id] = @id" InsertCommand="INSERT INTO [otherplace] ([id], [name], [url], [description]) VALUES (@id, @name, @url, @description)"
SelectCommand="SELECT [id], [name], [url], [description] FROM [otherplace]"
UpdateCommand="UPDATE [otherplace] SET [name] = @name, [url] = @url, [description] = @description WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="url" Type="String" />
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="url" Type="String" />
<asp:Parameter Name="description" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</asp:Content> 展开
源代码<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="abc.aspx.cs" Inherits="_Default" Title="abc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="id" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xiaolu %>"
DeleteCommand="DELETE FROM [otherplace] WHERE [id] = @id" InsertCommand="INSERT INTO [otherplace] ([id], [name], [url], [description]) VALUES (@id, @name, @url, @description)"
SelectCommand="SELECT [id], [name], [url], [description] FROM [otherplace]"
UpdateCommand="UPDATE [otherplace] SET [name] = @name, [url] = @url, [description] = @description WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="url" Type="String" />
<asp:Parameter Name="description" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="url" Type="String" />
<asp:Parameter Name="description" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</asp:Content> 展开
3个回答
展开全部
它的意思是说 你的gridview 必须放在含有runat=server的控件内
比如
<form id='form1' runat='server'>
gridview
</form>
比如
<form id='form1' runat='server'>
gridview
</form>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2009-06-05 · 知道合伙人金融证券行家
关注
展开全部
母版页中的 <form runat="server">是不是这样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询