DataSourceID="SqlSource"==>DataSourceID="SqlDataSource1"

解决方案 »

  1.   

    [HttpException (0x80004005): “DetailsView1”的 DataSourceID 必须是 IDataSource 类型的控件的 ID。未能找到 ID 为“SqlSource”的控件。] 
    关键是这里!你看看你的DetailsView1 的datasource绑定的是什么!确认是否正确
      

  2.   

    http://blog.csdn.net/robaot/archive/2009/09/28/4603305.aspx
    http://www.cnblogs.com/aaa6818162/archive/2009/05/07/1452016.html
      

  3.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="newsAdminDetail.aspx.cs" Inherits="newsAdminDetail" validateRequest="false"  %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1" runat="server"> 
        <title>新闻公告系统-管理 </title> 
        <link href="style.css" rel="stylesheet" type="text/css" /> 
    </head> 
    <body> 
        <a class="nav" href="newsAdmin.aspx">回到管理主页面 </a>&nbsp; 
                                                <asp:LoginStatus ID="LoginStatus2" runat="server" CssClass="nav" LogoutAction="Redirect" LogoutPageUrl="~/news.aspx" /> 
                                                &nbsp; &nbsp; </td> 
                                        </tr> 
                                        <tr style="font-size: 12pt; color: #000000"> 
                                            <td> 
                                                <img alt="" border="0" height="15" name="newsCenter_r3_c2" src="image/newsCenter_r3_c2.jpg" 
                                                    width="452" /> </td> 
                                        </tr> 
                                    </table> 
                                </td> 
                            </tr> 
                        </table> 
                    </td> 
                </tr> 
                <tr style="font-size: 12pt; color: #000000"> 
                    <td align="center" background="images/newsCenter_r4_c1.jpg" style="width: 644px"> 
                        <asp:LoginView ID="LoginView1" runat="server"> 
                            <AnonymousTemplate> 
                                <br /> 
                                <img src="image/shou.jpg" />请您先执行 
                                <asp:LoginStatus ID="LoginStatus1" runat="server" /> 
                                操作! <br /> 
                                <br /> 
                            </AnonymousTemplate> 
                            <LoggedInTemplate> 
                                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BorderWidth="0px" 
                                    Caption="新闻数据管理" CellPadding="4" CellSpacing="1" CssClass="forumline" DataKeyNames="news_id" 
                                    DataSourceID="SqlSource" DefaultMode="Edit" Height="50px" Width="95%"> 
                                    <CommandRowStyle HorizontalAlign="Center" /> 
                                    <RowStyle CssClass="row1" HorizontalAlign="Left" /> 
                                    <Fields> 
                                        <asp:TemplateField HeaderText="类别"> 
                                            <EditItemTemplate> 
                                                <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue=' <%# Bind("news_type") %>'> 
                                                    <asp:ListItem Selected="True">政治 </asp:ListItem> 
                                                    <asp:ListItem>经济 </asp:ListItem> 
                                        <asp:ListItem>文体 </asp:ListItem> 
                                        <asp:ListItem>生活 </asp:ListItem> 
                                        <asp:ListItem>其他 </asp:ListItem> 
                                                </asp:DropDownList> 
                                            </EditItemTemplate> 
                                            <InsertItemTemplate> 
                                                <asp:DropDownList ID="DropDownList2" runat="server" SelectedValue=' <%# Bind("news_type") %>'> 
                                                    <asp:ListItem Selected="True">政治 </asp:ListItem> 
                                                    <asp:ListItem>经济 </asp:ListItem> 
                                        <asp:ListItem>文体 </asp:ListItem> 
                                        <asp:ListItem>生活 </asp:ListItem> 
                                        <asp:ListItem>其他 </asp:ListItem> 
                                                </asp:DropDownList> 
                                            </InsertItemTemplate> 
                                        </asp:TemplateField> 
                                        <asp:TemplateField HeaderText="日期"> 
                                            <EditItemTemplate> 
                                                <asp:TextBox ID="TextBox1" runat="server" Text=' <%# Bind("news_date") %>'> </asp:TextBox> 
                                            </EditItemTemplate> 
                                            <InsertItemTemplate> 
                                                <asp:Label ID="Label1" runat="server" Text=" <%# System.DateTime.Now %>"> </asp:Label> 
                                            </InsertItemTemplate> 
                                        </asp:TemplateField> 
                                        <asp:BoundField DataField="news_subject" HeaderText="标题" SortExpression="news_subject" /> 
                                        <asp:BoundField DataField="news_editor" HeaderText="编辑者" SortExpression="news_editor" /> 
                                        <asp:TemplateField HeaderText="内容"> 
                                            <EditItemTemplate> 
                                                <asp:TextBox ID="TextBox2" runat="server" Height="100px" Text=' <%# Bind("news_content") %>' 
                                                    TextMode="MultiLine" Width="450px"> </asp:TextBox> 
                                            </EditItemTemplate> 
                                            <InsertItemTemplate> 
                                                <asp:TextBox ID="TextBox3" runat="server" Height="100px" TextMode="MultiLine" Width="450px" Text=' <%# Bind("news_content") %>'> </asp:TextBox> 
                                            </InsertItemTemplate> 
                                        </asp:TemplateField> 
                                        <asp:CommandField ShowEditButton="True" ShowInsertButton="True" /> 
                                    </Fields> 
                                    <AlternatingRowStyle CssClass="row2" /> 
                                </asp:DetailsView> 
                            </LoggedInTemplate> 
                        </asp:LoginView> 
                    </td> 
                </tr> 
                <tr style="font-size: 12pt; color: #000000"> 
                    <td style="height: 27px; width: 644px;"> 
                        </td> 
                </tr> 
            </table> 
        </div> 
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" <%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT * FROM [news] WHERE ([news_id] = ?)" 
                OnInserted="SqlDataSource1_Inserted" 
                OnUpdated="SqlDataSource1_Updated" 
                DeleteCommand="DELETE FROM [news] WHERE [news_id] = ?" 
                InsertCommand="INSERT INTO [news] ( [news_type], [news_subject], [news_content], [news_editor]) VALUES ( ?, ?, ?, ?)" 
                UpdateCommand="UPDATE [news] SET [news_type] = ?, [news_date] = ?, [news_subject] = ?, [news_content] = ?, [news_editor] = ? WHERE [news_id] = ?"> 
                <SelectParameters> 
                    <asp:QueryStringParameter Name="news_id" QueryStringField="news_id" Type="Int32" /> 
                </SelectParameters> 
                <DeleteParameters> 
                    <asp:Parameter Name="news_id" Type="Int32" /> 
                </DeleteParameters> 
                <UpdateParameters> 
                    <asp:Parameter Name="news_type" Type="String" /> 
                    <asp:Parameter Name="news_date" Type="DateTime" /> 
                    <asp:Parameter Name="news_subject" Type="String" /> 
                    <asp:Parameter Name="news_content" Type="String" /> 
                    <asp:Parameter Name="news_editor" Type="String" /> 
                    <asp:Parameter Name="news_id" Type="Int32" /> 
                </UpdateParameters> 
                <InsertParameters> 
                    <asp:Parameter Name="news_type" Type="String" /> 
                    <asp:Parameter Name="news_subject" Type="String" /> 
                    <asp:Parameter Name="news_content" Type="String" /> 
                    <asp:Parameter Name="news_editor" Type="String" /> 
                </InsertParameters> 
            </asp:SqlDataSource> 
        </form> 
    </body> 
    </html> 就这处DataSourceID="SqlSource"红线标记的,应改为DataSourceID = "SqlDataSource1"