62,072
社区成员
发帖
与我相关
我的任务
分享
<div class="title">信息大类:</div>
<div class="box">
<asp:DropDownList ID="ddlType" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlType_SelectedIndexChanged">
</asp:DropDownList></div></div>
<div class="gongying">
<div class="title">信息小类:</div>
<div class="box">
<asp:DropDownList ID="ddlInType" runat="server">
</asp:DropDownList></div></div>
public string str = "server=.;database=db_daikuan;uid=sa;pwd=";
public SqlConnection con;
public string sqlstr;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindType();
}
}
public void bindType()
{
sqlstr = "select '' as BigType union all select distinct BigType from tb_InfoType";
ddlType.DataSource = comds(sqlstr);
ddlType.DataValueField = "BigType";
ddlType.DataBind();
}
public void bindInType()
{
sqlstr = "select '' as MinType union all select MinType from tb_InfoType where BigType='" + ddlType.SelectedValue.Trim() + "'";
ddlInType.DataSource = comds(sqlstr);
ddlInType.DataValueField = "MinType";
ddlInType.DataBind();
}
public DataSet comds(string joinsql)
{
DataSet ds = new DataSet();
con = new SqlConnection(str);
SqlDataAdapter sda = new SqlDataAdapter(joinsql, con);
con.Open();
sda.Fill(ds);
con.Close();
return ds;
}
protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
sqlstr = "select '' as MinType union all select MinType from tb_InfoType where BigType='" + ddlType.SelectedValue.Trim() + "'";
ddlInType.DataSource = comds(sqlstr);
ddlInType.DataValueField = "MinType";
ddlInType.DataBind();
}