第二次下拉不会填充 [英] Second drop down does not populate

查看:72
本文介绍了第二次下拉不会填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面给出了代码片段。

The code snipnets are given below.

<asp:DropDownList ID="ddlState" runat="server" Height="28px" Width="354px" 

                            BorderColor="#C9CACA" BorderStyle="Solid" BorderWidth="1px" BackColor="White" 

                                change="UpdateDistrict()" >
                            
<script language="javascript" type="text/javascript">
    var xmlHttp;
    function UpdateDistrict()
    {
    xmlHttp = null;
    debugger;
    if(window.XMLHttpRequest)
    {
        xmlHttp = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    }
    
    if(xmlHttp != null)
    {
        var contName = document.getElementById('<%=ddlState.ClientID %>').value; 
        
        xmlHttp.onreadystatechange=state_Change;
        
        xmlHttp.open("GET","frmForAjaxCalls.aspx?cont="+contName,true);
        xmlHttp.send(null); 
    }
    }
</script>




public partial class frmForAjaxCalls : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Statename = Request.QueryString["cont"] as string;

        if (Statename != null)
        {
            DataTable table = Class1.getDistrictname(Statename);

            string result = string.Empty;

            foreach (DataRow r in table.Rows)
            {
                result += r["DistrictName"].ToString() + ";";
            }

            Response.Clear();
            Response.Write(result);
            Response.End();
        }
    }
}

this is within the class
public static DataTable getDistrictname(String StateSelected)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
        con.Open();
        SqlDataAdapter da2 = new SqlDataAdapter("select '--Not in List--' as DistrictName from tblMSTStateDistrict UNION select distinct DistrictName from tblMSTStateDistrict where Stateid ='" + Convert.ToString(StateSelected) + "' order by DistrictName", con);
        DataSet ds2 = new DataSet();
        da2.Fill(ds2);

        return ds2.Tables[0];
        con.Close();

    }

this is within the code file
onselectedindexchanged="ddlState_SelectedIndexChanged" onchange="UpdateDistrict()"

if (!PostBack)
{
SqlDataAdapter da1 = new SqlDataAdapter("select 0 as Stateid, '' as StateName from tblMSTStateMaster UNION select distinct Stateid, StateName from tblMSTStateMaster", con);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
ddlState.DataSource = ds1.Tables[0];
        ddlState.DataTextField = "StateName";
        ddlState.DataValueField = "StateID";
        ddlState.DataBind();

ddlDistrict.DataSource = Class1.getDistrictname(ddlState.SelectedValue);
        ddlDistrict.DataTextField = "DistrictName";
        ddlDistrict.DataValueField = "DistrictName";
        ddlDistrict.DataBind();
}



问题是该州正在填充。当没有回发时,控件也会变成 - 没有列表 - 。但是当我选择州时,区ddl没有被填充。此外它没有执行javascript updateDistrict()

请帮助我。


The problem is that the state is populating. The control is also fatching "--No in list--" when !not postback. But when I am selecting the state the district ddl is not getting populated. Moreover it is not executing the javascript updateDistrict()
Kindly help me out.

推荐答案

使用下面的链接你将得到一个例子

回发 [ ^ ]



注意:-Autopostback设置为true状态。
use below link you will get an example
postback[^]

Note:-Autopostback set to true of state.


这篇关于第二次下拉不会填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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