Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i bind dropdownliat in c# and i delete the item database using ajax. delete is successfull but list item diplay in dropdown list i use remove property in below the delete function but thats not properly remove any one please help me

What I have tried:

var x = document.getElementById("loginid");
x.remove(x.selectedIndex);
alert(x.selectedIndex);
this is my code
Posted
Updated 29-Mar-16 2:39am
Comments
Karthik_Mahalingam 29-Mar-16 7:26am    
your code looks fine.
post your related code on this. need to examine..
F-ES Sitecore 29-Mar-16 7:31am    
Do you see the right value in the alert box?
Nethaji chennai 29-Mar-16 7:37am    
alert is come 0
Nethaji chennai 29-Mar-16 7:32am    
public void bind()
{

string connString = ConfigurationManager.ConnectionStrings["autobuyConnectionString"].ToString();
// SqlCommand cmd = new SqlCommand("SELECT * FROM [dealer_userdetails]", new SqlConnection(ConfigurationManager.AppSettings["ConnString"]));
SqlConnection con = new SqlConnection(connString);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Dealer_user_drpdwn_UI1";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@employee", 1);


DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
loginid.DataSource = ds;
loginid.DataTextField = "username".ToUpper(); ;
loginid.DataValueField = "Dealerid";

loginid.DataBind();
con.Close();






//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["autobuyConnectionString"].ConnectionString);
//con.Open();
//SqlDataAdapter da = new SqlDataAdapter("Select * from dealer_userdetails order by username" , con);
//DataSet ds = new DataSet();
//DataTable dt = new DataTable();
//da.Fill(dt);
//da.Fill(ds);
//ListItem lst = new ListItem("SELECT DEALERNAME", "0");
//loginid.Items.Insert(loginid.Items.Count - 0, lst);
//if (ds.Tables[0].Rows.Count > 0)
//{
// loginid.Enabled = true;
// for (int i = 0; i < dt.Rows.Count; i++)
// {
// loginid.Enabled = true;
// loginid.Items.Add(dt.Rows[i][6].ToString().ToUpper());
// }
//}
//else
//{

// loginid.Enabled = false;
// // userName.Attributes.Add("disabled", "disabled");
//}

}
Nethaji chennai 29-Mar-16 7:37am    
the value removed but another another value deleted previous deleted value come

1 solution

Try this

var x = document.getElementById("loginid");
var options= x.options;
var selectedIndex ;
var dea = x.value;
for (var i= 0; i < options.length; i++) {
    if (options[i].value == dea ) {
        selectedIndex = i;
        break;
    }
}
alert(selectedIndex);
x.remove(selectedIndex);
 
Share this answer
 

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