0

嗨,我有几个下拉列表,但其中一个无法正常工作,当我从列表中选择并提交后,如果我从 Googlo Chrome 浏览,它将保持获取默认项目值并且不记录我从列表中选择的那个。我尝试清除缓存等,但它不起作用。这仅发生在一个下拉列表中,另一个运行良好。

下面是我的代码:

        <asp:TableRow>
            <asp:TableCell>Type:</asp:TableCell>
            <asp:TableCell>
                <asp:DropDownList ID="WOType" runat="server" DataSourceID="SqlDataSource1" DataTextField="WO_Type" DataValueField="WO_Type" AppendDataBoundItems="true">
                    <asp:ListItem Text="Select..." Value="" Selected="False" ></asp:ListItem>
                </asp:DropDownList>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ForeColor="Red" ErrorMessage=" Type is required." ControlToValidate="WOType"></asp:RequiredFieldValidator>

                <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:String %>' SelectCommand="SELECT [WO_Type] FROM [WOTYPE]"></asp:SqlDataSource>

            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>Product:</asp:TableCell>
            <asp:TableCell>
                <asp:DropDownList ID="Product_id" runat="server" DataSourceID="SqlDataSource2" DataTextField="Product_Product" DataValueField="Product_Product" AppendDataBoundItems="true">
                    <asp:ListItem Text="Select..." Value="" Selected="False" ></asp:ListItem>
                </asp:DropDownList>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ForeColor="Red" ErrorMessage=" Product is required." ControlToValidate="Product_id"></asp:RequiredFieldValidator>

                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:String %>" SelectCommand="SELECT [Product_Product] FROM [PRODUCT] ORDER BY [Product_Product]"></asp:SqlDataSource>

            </asp:TableCell>
        </asp:TableRow>

以下是代码背后的代码:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
            con.Open();
            string filename = Path.GetFileName(FileAttachment.PostedFile.FileName);
            string contentType = FileAttachment.PostedFile.ContentType;
            using (Stream fs = FileAttachment.PostedFile.InputStream)
            {

                using (BinaryReader br = new BinaryReader(fs))
                {
                    byte[] bytes = br.ReadBytes((Int32)fs.Length);
                    string constr = ConfigurationManager.ConnectionStrings["String"].ConnectionString;
                    using (SqlConnection conn = new SqlConnection(constr))
                    {

                        SqlCommand cmd = new SqlCommand("insert into WORKORDER(WOType,Product) values (@WOType,@Product)", conn);

                        cmd.Parameters.AddWithValue(@"WOType", WOType.Text);
                        cmd.Parameters.AddWithValue(@"Product", Product_id.Text);
                        conn.Open();
                        cmd.ExecuteNonQuery();

                        conn.Close();
                     }   
                  }
           }
   }   

Type 下拉列表可以返回我选择的列表,但 Product 下拉列表强制返回默认项。请帮忙

4

0 回答 0