Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Essentially what i'm trying to do is retrieve the user selections in detailsview, then insert those into my review table but I keep getting an error saying that it can't find the control. Any help would be amazing.

My code:
C#
<pre><asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="movieid" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px"  OnItemInserted="DetailsView1_ItemInserted">
            <Fields>
                  
                  
    <asp:TemplateField HeaderText="MovieTitle" SortExpression="Movieid">
                       <ItemTemplate>
     <asp:DropDownList ID="DropDownList1" runat="server"  autopostback="True"  DataSourceID="SqlDataSourceW2" DataTextField="MovieTitle" DataValueField="MovieId"></asp:DropDownList>
  <asp:SqlDataSource ID="SqlDataSourceW2" runat="server" ConnectionString="<%$ ConnectionStrings:Database1ConnectionString %>" ProviderName="<%$ ConnectionStrings:Database1ConnectionString.ProviderName %>" SelectCommand="SELECT [MovieID], [MovieTitle] FROM [movies_table] ORDER BY [Movietitle]"></asp:SqlDataSource>

                      </ItemTemplate> 
</asp:TemplateField>
                      <asp:BoundField DataField="rating" HeaderText="rating" SortExpression="rating" />
                <asp:BoundField DataField="review" HeaderText="review" SortExpression="review" />
          

                <asp:CommandField ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
    
    </div>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Database1ConnectionString %>"  
           SelectCommand="select review_table.movieid, movies_table.movieid, review, rating, from review_table, movies_table
           where Review_table.movieID = @Title order by movies_table.movietitle;" 
           InsertCommand="insert into [REVIEW_TABLE] ([UserName], [MovieID], [MovieTitle], [Rating], [Review]) values (?,?,?,?,?)" 
           ProviderName="<%$ ConnectionStrings:Database1ConnectionString.ProviderName %>" >

            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="Title" PropertyName="SelectedValue" defaultvalue="0"  />
            </SelectParameters>

        <InsertParameters>
            <asp:SessionParameter Name="UserName" SessionField="UserName" Type="String" />
            <asp:Parameter Name="MovieID" Type="String" />
            <asp:Parameter Name="MovieTitle" Type="String" />
            <asp:Parameter Name="Rating" Type="String" />
            <asp:Parameter Name="Review" Type="String" />
        </InsertParameters>

            
        </asp:SqlDataSource>
      
         <asp:GridView ID="GridReview" runat="server" AutoGenerateColumns="False" DataKeyNames="MovieID" DataSourceID="SqlDataSource1">
            <Columns> 
                <asp:BoundField DataField="movietitle" HeaderText="movieid" InsertVisible="True" ReadOnly="True" SortExpression="movieid" />
                <asp:BoundField DataField="UserName" HeaderText="User" SortExpression="UserName" />
                <asp:BoundField DataField="review" HeaderText="Review" SortExpression="review" />
                <asp:BoundField DataField="rating" HeaderText="Rating" SortExpression="rating" />
            </Columns>
        </asp:GridView>


Behind the code:
C#
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["firstname"] == null)
        {
            Response.Redirect("login.aspx");
           
        }
    }




    protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        
        Session["UserName"] = HttpContext.Current.User.Identity.Name;
    
        GridReview.DataBind();



    }
}



The error:
C#
Server Error in '/' Application.
Could not find control 'DropDownList1' in ControlParameter 'Title'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Could not find control 'DropDownList1' in ControlParameter 'Title'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: Could not find control 'DropDownList1' in ControlParameter 'Title'.]
   System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +2751368
   System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +50
   System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +101
   System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +46
   System.Web.UI.Page.OnLoadComplete(EventArgs e) +9758546
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +776


What I have tried:

followed whats on msdn.microsoft.com related to this
Posted
Comments
[no name] 11-May-18 20:40pm    
You are having AutoPostBack set True for DropDownList1, did you checked if you loading this control and populating correctly after postback

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900