0

I have a page I need to modify. The page was written by another developer. The page already had a combobox and function that allowed the user to select an author's name, click a button, then add that author's name to their wish list. I need to add another combobox that displays the library's genres, display the authors associated with that genre, then allow the user to click a button and add all those authors to their reading wish list. Here is the code with both the author and the genre comboboxes and the script that I'm attempting to use to insert all the authors when a genre is selected:

<asp:DropDownList ID="ddlGenres" runat="server" DataSourceID="SqlDataSourceLibros" 
     DataTextField="Genre_Name" DataValueField="GenreID" 
     onselectedindexchanged="genreList_SelectedIndexChanged" AutoPostBack="True" AppendDataBoundItems="true">
    <asp:ListItem Value="0">Groups</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1Libros" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Libros %>" 
        SelectCommand="SELECT [GenreID],[Genre_Name] FROM [Library_Genres] ORDER BY [Genre_Name]">        
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
        DataSourceID="SqlDataSourceLibros2" DataTextField="Author_Name"  EnableViewState="false"
        DataValueField="Genre_Name">
</asp:DropDownList>
<asp:ImageButton ImageUrl="~/buttons/addGenre.png" Height="18px"  
          OnMouseOver="this.src='../buttons/addGenreHover.png'" 
          OnMouseOut="this.src='../buttons/addGenre.png'" 
          ToolTip="Add Library Genre" runat="server"  ID="btnAddGenre"  
          OnClick="btnAddGenre_Click" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Libros %>"         
        SelectCommand="SELECT [Author_Name] FROM [Library_authors] WHERE ([Genre_Name] = @Genre_Name)">
   <SelectParameters>
       <asp:ControlParameter ControlID="ddlGroups" Name="Author_Name" 
                PropertyName="SelectedValue" Type="String" />
   </SelectParameters>
</asp:SqlDataSource>

And now the script that is called by clicking the button:

protected void btnAddAuthors(object sender, EventArgs e)
{
        odsAuthors.Insert();
        AuthorList.ClearSelection();
        Response.Redirect(Request.Url.AbsoluteUri);
}

protected void btnAddGenre(object sender, EventArgs e)
{
        SqlDataSourceLibros2.Insert();
        ddlGenres.ClearSelection();
        Response.Redirect(Request.Url.AbsoluteUri);
}

My problem is that when I click the Add Genres button, the event that adds the individual author fire and is inserted - not all of the authors that appear in the combo box - depending on what genre is selected.

How can I get the list of authors to be inserted into the database like the individual author is inserted into the database when the AddAuthors button is clicked?

4

1 回答 1

0

检查这个答案,你不能使用普通的选择框 - 因为它实际上只有一个值,你应该使用控件进行多项选择,之后 - 你不能用作者填充它们,它们都被选中/选中,然后你会得到所有C# 代码中的值,然后您将能够使用 for 将它们全部插入

于 2013-10-10T19:49:00.443 回答