Hello, I have a question about getting the id of a book author and adding it to the creation of a book, and the book to be published should have an Auto Increasing Book ID, a book name, and the author ID.
My question is to get the author ID obtained through the Request.QueryString and add it to the books table and the error that could not be found control 'AutorID' in 'AutorID' ControlParameter.
function Page_Load
to get 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>
setting 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 enter 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>