Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DropDownList_Binding not working on selected_index changed at Global server But it's working well on localhost.
after selecting value both are displaying empty on global server but not on Localhost.
can any one help me to fix this problem. ..
the code is given below:

.cs code:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindMake();
}
}


public void BindMake()
{
SqlConnection objcon = new SqlConnection();
objcon.ConnectionString = "Data source=localhost; Initial catalog=ddlbind; User ID=sa; Password=;";
SqlCommand objcmd = new SqlCommand();
objcmd.CommandType = CommandType.Text;
objcmd.CommandText = "Select * from country";
objcmd.Connection = objcon;
objcon.Open();
SqlDataReader dr;
dr = objcmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "countryname";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
objcon.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("hello");

int selectedid = Convert.ToInt32(DropDownList1.SelectedValue);
SqlConnection objcon = new SqlConnection();
objcon.ConnectionString = "Data source=localhost; Initial catalog=ddlbind; User ID=sa; Password=;";
SqlCommand objcmd = new SqlCommand();
objcmd.CommandType = CommandType.Text;
objcmd.CommandText = "Select * from city where cid='" + selectedid + "'";
objcmd.Connection = objcon;
objcon.Open();
SqlDataReader dr;
dr = objcmd.ExecuteReader();
DropDownList2.DataSource = dr;
DropDownList2.DataTextField = "cityname";
DropDownList2.DataBind();
objcon.Close();
}
}




.aspx code is this:

XML
<table align="center" class="style1">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:Label ID="Label1" runat="server" Text="Country"></asp:Label>
            </td>
            <td>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                </asp:DropDownList>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:Label ID="Label2" runat="server" Text="City"></asp:Label>
            </td>
            <td>
                <asp:DropDownList ID="DropDownList2" runat="server">
                </asp:DropDownList>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
    </table>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900