Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have Dictionary("statecode","statename").
When I use StateList on button click it is null. I can understand why it is.
I want to know how to use StateList in javascript.


C#
 Dictionary<string, string> StateList = null;
protected void Page_Load(object sender, EventArgs e)
       {
          if (!IsPostBack)
            {
          GetState();
}
}
internal Dictionary<string, string> GetState()
        {

            try
            {
                StateList = new Dictionary<string, string>();
                using (cmd = new SqlCommand("sp_MstState", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@StateCode", ""));
                    cmd.Parameters.Add(new SqlParameter("@StateName", ""));
                    cmd.Parameters.Add(new SqlParameter("@Mode", "S"));
                    if (con.State == ConnectionState.Closed)
                        con.Open();
                    da = new SqlDataAdapter(cmd);
                    ds = new DataSet();
                    da.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            
                            StateList.Add(dr["StateCode"].ToString(), dr["StateName"].ToString());
                        }
                    }
                }

            }
            catch (Exception ex)
            {
            }
            finally
            {
                
                con.Close();
            }
            return StateList;
        }
Posted
Updated 10-Oct-13 21:10pm
v2
Comments
coded007 28-Oct-13 10:13am    
Can we have the code for "sp_MstState" ?

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