我有一个DropDownList,其中包含我从SQL数据库获取的值。根据DropDownList的选择,我也填充了一个GridView,也来自SQL数据库。
当我在DropDownList上设置AutoPostBack = true时,我得到一个'输入字符串格式不正确'错误。
我的DropDownList:
<html>
<asp:DropDownList ID="ddlClient" runat="server" DataSourceID="dsClientList" AppendDataBoundItems="True" DataTextField="Name" DataValueField="Name" TabIndex="0" Font-Names="Verdana" Font-Size="11px" ForeColor="#2D2D2D" AutoPostBack="true">
<asp:ListItem Value="">--- Select ---</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="dsClientList" runat="server" SelectMethod="GetList" TypeName="Class.Client">
</asp:ObjectDataSource>
</html>
在我的GridView的ObjectDataSource中,我使用以下SelectParameters:
<SelectParameters>
<asp:ControlParameter ControlID="ddlClient" Name="pClientID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
任何帮助?
由于
答案 0 :(得分:3)
可能正在尝试将此列表项的值转换为int
<asp:ListItem Value="">--- Select ---</asp:ListItem>
空字符串无法转换为整数,请尝试使用-1或0。
答案 1 :(得分:1)
您必须为DataValueField="Name".
设置数字列,可以是ID
或Number
。
<asp:DropDownList ID="ddlClient" runat="server" DataSourceID="dsClientList"
AppendDataBoundItems="True"
DataTextField="Name"
DataValueField="pCientID"
.....
答案 2 :(得分:0)
您可以尝试设置--- Select ---
的默认值,如果设置无法解析为Int32的空白""
,则可以使用以下代码块:
<html>
<asp:DropDownList ID="ddlClient" runat="server" DataSourceID="dsClientList" AppendDataBoundItems="True" DataTextField="Name" DataValueField="yourClientIDField" TabIndex="0" Font-Names="Verdana" Font-Size="11px" ForeColor="#2D2D2D" AutoPostBack="true">
<asp:ListItem Value="0">--- Select ---</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="dsClientList" runat="server" SelectMethod="GetList" TypeName="Class.Client">
</asp:ObjectDataSource>
</html>