4
Answers

My Dropdownlist always take the 1st value of database

if (Session["User_Name"] == null)
{
Response.Redirect("Salon.aspx");
}
else
{
IEnumerator mc;
mc = Request.Cookies.AllKeys.GetEnumerator();
while (mc.MoveNext())
{
if (Request.Cookies[mc.Current.ToString()].HasKeys == true)
{
IEnumerator sc;
sc = Request.Cookies[mc.Current.ToString()].Value.GetEnumerator();
if (!Page.IsPostBack)
{
Wella.Visible = false;
Sebastian.Visible = false;
Nioxin.Visible = false;
illumina.Visible = false;
DropDownList1.AutoPostBack = true;
string Value = DropDownList1.SelectedValue;
lbUserName.Text = "WELCOME:: " + Session["User_Name"];
SqlConnection con = new SqlConnection(ConStr);
{
SqlCommand com = new SqlCommand("select User_Name,Company_Name from tblCompany where User_Name='" + Session["User_Name"] + "' ", con);
{
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "Company_Name";
DropDownList1.DataValueField = "User_Name";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("---Select---", String.Empty));
DropDownList1.SelectedIndex = 0;
}
}
}
}
}
}
Answers (4)
0
eksypnos123

eksypnos123

NA 65 0 20y
Much easier to create an insert command object and then run it using executeNonQuery() You just set the value for the Name, ID will be handled by the database. and by the way, this is C# forum, so what's this Dim overthere?