我有一个文本框,我需要将其传递authorid
到与所选作者匹配的隐藏字段中。然后我需要将其传递authorID
给 response.redirect url,以便在单击按钮时打开详细的作者页面,其中包含该作者的传记信息。
下面是我的代码,但它不起作用。
如何让我的按钮工作,以便在每次选择作者姓名时传递正确的 authorid?
ImageButton btnFindAuthors = sender as ImageButton;
HiddenField myhiddenfield = btnFindAuthors.NamingContainer.FindControl("hiddenID") as HiddenField;
int myID = Convert.ToInt32(myhiddenfield.Value);
Response.Redirect(String.Format("~/Authors_Detail.aspx?id=" + myhiddenfield));
标记:
<asp:TextBox runat="server" ID="txtAuthors" Text='<%# Bind("AuthorName") %>' />
<asp:ImageButton runat="server" ID="btnFindAuthors" OnClick="btnFindAuthors"/>
<ajaxToolkit:AutoCompleteExtender ID="fndAuthors" runat="server"
DelimiterCharacters="" Enabled="True"
ServicePath="~/WebServices/AuthorsWebService.asmx"
ServiceMethod="AutoComplete"
TargetControlID="txtAuthors" MinimumPrefixLength="3" />
<asp:HiddenField ID="hiddenID" runat="server" Value='<%#Eval("AuthorID") %>' />
作者编号:
<asp:SqlDataSource runat="server" ID="sqlAuthors"
ConnectionString="<%$ ConnectionStrings:Libros %>"
ProviderName="<%$ ConnectionStrings:Libros.ProviderName %>"
SelectCommand="SELECT * FROM Authors
WHERE AuthorName LIKE ('%' + @Authorname + '%')
ORDER BY AuthorName"
<selectParameters>
<asp:ControlParameter ControlID="txtAuthors" Name="authorname" />
</selectParameters>
</asp:SqlDataSource>