ASP.NET - UI problem - Asked By mostafa hamdy on 12-Mar-12 08:24 AM

Hello all
I have some web site have page contains dropdown list filled in with employees and behid the Dropdown I have some button which open popup window to add employees , I want when the user add employee successfully the new employee added to the employee dropdown list with out page post page is there's any way to do that ? please if any bodt get what I mean and can help me please send me or tell me about some URL may help me in doing that
Regards
Mostafa
dipa ahuja replied to mostafa hamdy on 12-Mar-12 09:06 AM
Create a method :

void bindDropDonw()
{
  SqlDataAdapter da = new SqlDataAdapter("select empid from emp", "ConnectionString");
 
  DataTable dt = new DataTable();
  da.Fill(dt); // Fill the dataset
 
  DropDownList1.DataSource = dt;
  DropDownList1.DataValueField = "empid";
  DropDownList1.DataTextField = "empid";
  DropDownList1.DataBind();
}
 
Now call this method after adding new value .
kalpana aparnathi replied to mostafa hamdy on 12-Mar-12 02:49 PM
hi,

Try with this code:

using System;
  using System.Web;
  using System.Collections;
  using System.Collections.Generic;
  using System.Collections.Specialized;
  using System.Web.Services;
  using System.Web.Services.Protocols;
  using AjaxControlToolkit;
  using System.Data;
  using System.Data.SqlClient;
 
  /// <summary>
  /// Summary description for CarData
  /// </summary>
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  public class CarData : System.Web.Services.WebService
  {
    public CarData()
    {
    //Uncomment the following line if using designed components
    //InitializeComponent();
    }
 
    [WebMethod]
    public CascadingDropDownNameValue[] GetMakes(
    string knownCategoryValues,
    string category)
    {
    CarsTableAdapters.MakeTableAdapter makeAdapter =
      new CarsTableAdapters.MakeTableAdapter();
    Cars.MakeDataTable makes = makeAdapter.GetMakes();
    List<CascadingDropDownNameValue> values =
      new List<CascadingDropDownNameValue>();
    foreach (DataRow dr in makes)
    {
      string make = (string)dr["Make"];
      int makeId = (int)dr["MakeID"];
      values.Add(new CascadingDropDownNameValue(
      make, makeId.ToString()));
    }
    return values.ToArray();
    }
 
    [WebMethod]
    public CascadingDropDownNameValue[] GetModelsForMake(
    string knownCategoryValues,
    string category)
    {
    StringDictionary kv =
    CascadingDropDown.ParseKnownCategoryValuesString(
      knownCategoryValues);
    int makeId;
    if (!kv.ContainsKey("Make") ||
      !Int32.TryParse(kv["Make"], out makeId))
    {
      return null;
    }
    CarsTableAdapters.ModelTableAdapter makeAdapter =
      new CarsTableAdapters.ModelTableAdapter();
    Cars.ModelDataTable models =
      makeAdapter.GetModelsForMake(makeId);
    List<CascadingDropDownNameValue> values =
      new List<CascadingDropDownNameValue>();
    foreach (DataRow dr in models)
    {
      values.Add(new CascadingDropDownNameValue(
      (string)dr["Model"], dr["ModelID"].ToString()));
    }
    return values.ToArray();
    }
 
    [WebMethod]
    public CascadingDropDownNameValue[] GetColorsForModel(
    string knownCategoryValues,
    string category)
    {
    StringDictionary kv =
      CascadingDropDown.ParseKnownCategoryValuesString(
      knownCategoryValues);
    int modelId;
    if (!kv.ContainsKey("Model") ||
      !Int32.TryParse(kv["Model"], out modelId))
    {
      return null;
    }
    CarsTableAdapters.ColorTableAdapter adapter =
      new CarsTableAdapters.ColorTableAdapter();
    Cars.ColorDataTable colorTable =
      adapter.GetColorsForModel(modelId);
    List<CascadingDropDownNameValue> values =
      new List<CascadingDropDownNameValue>();
    foreach (DataRow dr in colorTable)
    {
      values.Add(new CascadingDropDownNameValue(
      (string)dr["Color"], dr["ColorID"].ToString()));
    }
    return values.ToArray();
    }

Regards,
mostafa hamdy replied to kalpana aparnathi on 13-Mar-12 04:32 AM
Hello all
many thanks about ur replies , but really none of what u have send me is what I mean , I mean again is I have drop down list filled in with employees , and theres some button in the same page when the user clicked it some pop-up window for adding employees appears to him/her to enable the user to add new employee, what I want is when the new Employee added the dropdown of the employees updated with the new employee added , that's all I wish my question is clear and wish some body can help me to do that , thanx again and waiting ur help
regards
Mostafa