Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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:
 
<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 31-Oct-12 5:12am

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 295
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 31 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100