Unable to locate Control ID in Controlparameter - Asp.Net

Asked

Viewed 127 times

0

Hello, I’m having a question getting the id of a book author and adding it to a book creation, and the book to be published should have an auto-incrementing Book ID, a book name and the author ID.

My question is to get the author ID obtained through Request.Querystring and add it to the table of books and the error that could not find 'Autorid' control in 'Autorid' Controlparameter.

function Page_Load to obtain the nome and id of autor to show in div title

protected void Page_Load(object sender, EventArgs e) {

  //obter o id do autor
  int autorId = Convert.toInt32(Request.QueryString["id"]);
  //obter o nome do autor
  string autorNome = Request["nome"];

  if (!IsPostBack) {
    if (autorNome != null) {
        AutorNomeLabel.Text = autorNome;
        AutorIDLabel.Text = Convert.toString(autorId);
    }
  }
}

in this div with title as id that shows the name and id of autor

<div id="titulo">
  <h1>
  <asp:Label ID="AutorNomeLabel" runat="server" />
  <asp:Label ID="AutorIDLabel runat="server" />
 </h1>
</div>

the configuration of SqlDataSource

<asp:SqlDataSource ID="LivrariaSqlDataSource" runat="server" 
 ConnectionString="<%$ ConnectionStrings:Livraria %>" 
 SelectCommand="SELECT [AutorID] FROM [Autor] WHERE [AutorNome] = @AuthorNomeLabel" 
 InsertCommand="INSERT INTO [Livros] ([NomeLivro],[AutorID]) VALUES (@NomeLivro,@AutorID)">
  <SelectParameters>
    <asp:ControlParameter Name="AutorID" ControlID="AuthorNomeLabel" Type="Int32" />
  </SelectParameters>
  <InsertParameters>
    <asp:Parameter Name="NomeLivro" Type="String" />
    <asp:Parameter Name="AutorID" Type="Int32" />
  </InsertParameters>
</asp:SqlDataSource>

Template to insert the name and author of Livro

<InsertItemTemplate>
  Book Name:
  <asp:TextBox ID="NomeLivro" runat="server" CssClass="textBox" 
       Text='<%# Bind("NomeLivro")%>' />
  <asp:HiddenField ID="AutorID" runat="server" Value='<%# Bind("AutorID") %>' />
</InsertItemTemplate>
  • I find it interesting to add the tag webforms

  • @jefersonb, thanks, already added...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.