DropDownList SelectIndexChanged不工作?

时间:2016-12-03 15:41:27

标签: asp.net

这似乎是一个常见问题。我尝试了不同的解决方案,但它仍然无效。这是我的代码。

HTML:

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

        if editingStyle == UITableViewCellEditingStyle.delete {
            let managedObjectContext: NSManagedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext;
            let managedObject: NSManagedObject = fetchedResultsController.object(at: indexPath) as! NSManagedObject;
            managedObjectContext.delete(managedObject);
            do {
                try managedObjectContext.save();
                tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.fade);
            } catch {
                // Error occured while deleting objects
            }



        } else if editingStyle == UITableViewCellEditingStyle.insert {

        }

    }

功能:OnSelectedIndexChanged

<div class="form-group">
  <label for="exampleInputEmail1">Artist *</label>
  <asp:DropDownList ID="artistDropdown" runat="server" CssClass="form-control" AutoPostBack="True" OnSelectedIndexChanged="artistDropdown_SelectedIndexChanged" ViewStateMode="Enabled"></asp:DropDownList>
  <asp:TextBox ID="mytest" runat="server"></asp:TextBox>
  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="artistDropdown" SetFocusOnError="true" ErrorMessage="Required Field" Font-Bold="True" Font-Names="Arial" Font-Size="X-Small" ForeColor="Red"></asp:RequiredFieldValidator>
  <asp:Label ID="lblMessage" runat="server" CssClass="help-block" Visible="False">Cant select Artist with no Manager</asp:Label>
</div>

我在protected void artistDropdown_SelectedIndexChanged(object sender, EventArgs e) { string selectedArtist = artistDropdown.SelectedValue; mytest.Text = selectedArtist; string query = "Select [Manager ID] from Artist Where ID = '" + selectedArtist + "'"; string myConnection = dbController.connectionString; SqlConnection conn = new SqlConnection(myConnection); SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); object obj = cmd.ExecuteScalar(); if (obj is System.DBNull) { artistDropdown.SelectedValue = ""; lblMessage.Visible = true; } else { lblMessage.Visible = false; } conn.Close(); } 函数中加载DropDownList,并为DropDownList设置Page_Load()

我还创建了一个TextBox,它从DropDownList设置为selectedValue,以检查OnSelectedIndexChanged是否正在触发。但是文本框仍然是空的。

我做错了什么?

0 个答案:

没有答案