0
<table><tr>
   <td>
      Type:
   </td>
    <td>
       <asp:DropDownList ID="ddltype" runat="server" OnSelectedIndexChanged="ddltype_SelectedIndexChanged">
       <asp:ListItem Value="0">---select---</asp:ListItem>
       <asp:ListItem Text="Setter" Value="1">
       </asp:ListItem>
       <asp:ListItem Text="Getter" Value="2"></asp:ListItem>
       </asp:DropDownList>
    </td>
       <td>
          Name:
       </td>
            <td>
              <asp:DropDownList ID="ddlname" runat="server">
              </asp:DropDownList>
            </td>
 </tr> </table>

如果用户在第一个下拉列表中选择setter或选择getter,我想在第二个下拉列表中填写相关名称。如何在 c# 页面中编写代码以满足此要求。请任何人帮助我。

4

1 回答 1

1
 public void NamesToDropdownList()
{
        objhatcheryPL.type = ddltype.SelectedItem.Text;
        DataTable dtname = new DataTable();
        dtname = objhatcheryBAL.dtnames(objhatcheryPL);
        ddlname.DataTextField = "Name";
        ddlname.DataValueField = "Name";
        ddlname.DataSource = dtname;
        ddlname.DataBind();
        ddlname.Items.Add(new ListItem("--select--", "0"));
        ddlname.SelectedIndex = ddlname.Items.Count - 1;
 }

protected void ddltype_SelectedIndexChanged(object sender, EventArgs e)
   {
    if (ddltype.SelectedItem.Text != "--Select--")
    {
        NamesToDropdownList();
    }
   }

有了这个,我的代码运行良好....

于 2013-10-30T09:16:45.007 回答