使用回发,根据另一个下拉列表中的选择填充一个Asp.net下拉列表 [英] Populate One Asp.net Dropdown based on Selection in Another Dropdown withourt using postback

查看:61
本文介绍了使用回发,根据另一个下拉列表中的选择填充一个Asp.net下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下拉列表中的数据来自数据库。



The Data in dropdownlist is come from database.

If (!IsPostBack)
         {
             Bindcategorydown();
         }

    

    protected void Bindcategorydown()
    {
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");
        con.Open();
        SqlCommand cmd = new SqlCommand("SELECT * from CAT_DETAIL", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddCat.DataSource = ds;
        ddCat.DataTextField = "CAT_DESC";
        ddCat.DataValueField = "CAT_ID";
        ddCat.DataBind();
        ddCat.Items.Insert(0, new ListItem("Select A Category...", "-1"));
        ddSubCat.Items.Insert(0, new ListItem("--Select--", "-1"));

    }


    protected void ddCat_SelectedIndexChanged(object sender, EventArgs e)
    {
        int Cat_ID = Convert.ToInt32(ddCat.SelectedValue);
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");
        con.Open();
        SqlCommand cmd = new SqlCommand("SELECT * FROM SUB_CAT_DETAIL WHERE CAT_ID=" + Cat_ID, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddSubCat.DataSource = ds;
        ddSubCat.DataTextField = "SUB_CAT_DESC";
        ddSubCat.DataValueField = "SUB_CAT_ID";
        ddSubCat.DataBind();
        ddSubCat.Items.Insert(0, new ListItem("Select A Sub-Category...", "-1"));

    }





我正在使用autopostback,但我不想在重新加载时重新加载整个页面。



I am using autopostback but i dont want to reload whole page as it reload.

推荐答案

在ASP.NET Update Panel中包装两个下拉列表并将第二个更新面板的Trigger As设置为第一个下拉列表的选定索引更改事件
Wrap both dropdowns in ASP.NET Update Panel and set the 2nd update panel 's Trigger As first dropdown's selected index change event


为此你必须使用 jQuery。



样本一如下:



For that you have to use jQuery.

Sample one is as below:

<script type="text/javascript">
  Sys.require('jQuery', function () {
      var ownerKey = ui.draggable.data('owner-key');
                    var providerKey = '<%: Model.Provider.Key %>';


.ajax({
url:/ Portal / GetPurchasedPackages,
dataType:'json',
data:{ownerKey:ownerKey,providerKey:providerKey},
success:function(data){
.ajax({ url: "/Portal/GetPurchasedPackages", dataType: 'json', data: { ownerKey: ownerKey, providerKey: providerKey }, success: function (data) {


这篇关于使用回发,根据另一个下拉列表中的选择填充一个Asp.net下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆