Iveは、データベースから製品のTotalQuantityを取得し、製品を追加する際に範囲バリデーターの最大値として使用しようとしましたカートに。 私は、フロントエンドのコードを使用:データベースasp.netから範囲バリデーターの最大値を動的に取得し、intに変換
<td class="style2">
QUANTITY<br />
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="must fill some value"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="must fill value lesser than the Total Quantity in stock"
MaximumValue="<%=maxValue %>" MinimumValue="1" Display="Dynamic" ></asp:RangeValidator>
<br />
バックエンドCSコードは次のとおりです。
public partial class productDetail : System.Web.UI.Page
{
public int maxValue=0;
public int minValue = 1;
.....
protected void Page_Load(object sender, EventArgs e)
{
//Defined SQL Conn string...
connection1.Open();
string cartCmd = "select TotalQuantity from Product where ProductName= \'"+prodName+"\';";
SqlCommand cmd = new SqlCommand(cartCmd, connection1);
SqlDataReader readerTotQquantity = cmd.ExecuteReader();
if (readerTotQquantity .HasRows)
{
readerTotQquantity .Read();
TotalQuantity = readerTotQquantity ["TotalQuantity"].ToString();
}
double val = Convert.ToDouble(TotalQuantity);
maxValue = (int)val;
// also tried maxValue=Convert.ToInt32(TotalQuantity);
// tired maxValue=int.Parse(TotalQuantity); etc
connection1.Close();
}
}
私は疲れてVisual Studioの出力パネル上の値を印刷し、それが正しい値とを示しますSystem.Int32と入力します。ページのエラーは "The MaximumValue <%= maxValue%>がRangeValidator1のMinimumValue 1より小さくなることはできません"と表示されます。
また、RangeValidatorにType = "Integer"を追加/削除しても何度か試してみましたが、エラーはそのまま残ります。 Plsは私の時間の数時間を費やして、どこが間違っているのか把握しようとしています。
が私のために働きました。どうもありがとう! – user3387677