Click here to Skip to main content
14,977,142 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
Karthik_Mahalingam 29-Mar-16 7:53am
   
yes, if the existing value is deleted then the next value will be shown in the list box.
Nethaji chennai 29-Mar-16 7:55am
   
tell me any another way
Karthik_Mahalingam 29-Mar-16 8:00am
   
what is your exact issue ? still not clear with your problem..
Nethaji chennai 29-Mar-16 8:12am
   
i delete the dropdown list selected item.delete is successfull but item is displaying in dropdown list . after i page reload the item will removed . i want without page load
Karthik_Mahalingam 29-Mar-16 8:20am
   
post your aspx code.
Nethaji chennai 29-Mar-16 8:25am
   
<script type="text/javascript">
function del() {


var dea = document.getElementById("loginid").value;
document.getElementById('loading').style.visibility = "visible";
if (dea > 0) {

$.ajax({



type: "POST",
url: "http://app2.autobuycrm.com/autobuynew.asmx/Dealer_Delete_UI",
data: "{'dealerid':'" + dea + "'}",
contentType: "application/json;chanrset=utf-8",
dataType: "json",
success: function (msg) {

var re = msg.d;
var n = re.search("failed");
// alert(n);
if (n == -1) {
document.getElementById("inner").innerHTML = "DEALER DELETED";
modal.style.display = "block";


$("#loginid option:selected").remove();

document.getElementById("CheckBox1").checked = false;
document.getElementById("CheckBox2").checked = false;
document.getElementById("CheckBox3").checked = false;
document.getElementById("CheckBox4").checked = false;
var objSel = document.getElementById("loginid");
objSel.options[0] = new Option("SELECT DEALERNAME", "0");
document.getElementById("loginid").value = 0;

document.getElementById("address").value = '';
document.getElementById("name_of_dealership").value = '';
document.getElementById("tinno").value = '';
document.getElementById("city").value = '';
document.getElementById("state").value = '';
document.getElementById("zip").value = '';
document.getElementById("phone").value = '';
document.getElementById("wesite").value = '';
document.getElementById("pri_contact").value = '';
document.getElementById("pr_email").value = '';
document.getElementById("PasswordConfirmTextbox").value = '';
document.getElementById("txtFirstName").value = '';
document.getElementById("txtLastName").value = '';
document.getElementById("PasswordTextbox").value = '';
document.getElementById("userid").value = '';
document.getElementById("dealerid").value = '';
document.getElementById('inner').value = '';
document.getElementById('loading').style.visibility = "hidden";


}
else {

document.getElementById("inner").innerHTML = " CANNOT DELETE SELECTED DEALERNAME";
modal.style.display = "block";
document.getElementById('loading').style.visibility = "hidden";
}

var objSel = document.getElementById("loginid");
objSel.options[0] = new Option("SELECT DEALERNAME", "0");

document.getElementById("loginid").value = 0;
document.getElementById("address").value = '';
document.getElementById("name_of_dealership").value = '';
document.getElementById("tinno").value = '';
document.getElementById("city").value = '';
document.getElementById("state").value = 0;
document.getElementById("zip").value = '';
document.getElementById("phone").value = '';
document.getElementById("wesite").value = '';
document.getElementById("pri_contact").value = '';
document.getElementById("pr_email").value
Karthik_Mahalingam 29-Mar-16 8:50am
   
check my solution.

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);
   

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