感謝非常有幫助的答案,我已經能夠修改我的頁面,所以我的下拉框正確更新了SQL查詢中選定的結果。c#錯誤 - 輸入字符串格式不正確
我測試的最後一個階段是將更改後的記錄更新到數據庫中。無論我做什麼,我總是收到錯誤 - 輸入字符串的格式不正確。
它看起來像正在傳遞的文本值,而不是作者的ID - 但我已經在數據值字段中標識了AuthorID。下面是我的代碼:
protected void btnAddAuthors(object sender, EventArgs e)
{
odsIdentifiedAuthors.Insert();
lbAuthors.ClearSelection();
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void groupList_TextSelected(object sender, EventArgs e)
{
lbUserList.Items.Clear();
lbUserList.Items.Add(new ListItem(DropDownList1.SelectedItem.Text, DropDownList1.SelectedItem.Text));
lbUserList.Items.FindByValue(DropDownList1.SelectedItem.Text).Selected = true;
}
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlDataSource2" DataTextField="Author_Name" EnableViewState="false"
DataValueField="ID" OnSelectedIndexChanged="AuthorsList_TextSelected" AutoPostBack="true">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:Libros %>"
SelectCommand="SELECT [Author_Name], [AuthorID] FROM [Authors] WHERE ([Genre] = @Genre)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlAuthors" Name="Genre"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
如何解決這個問題?
哪一行是給錯誤? – Harrison
執行btnAddAuthors事件時發生錯誤。 – user2821300