Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using C#,asp.net 2.0,server 2005 and visual studio 2005

Can anybody help with the following dropdownlist problem in asp.net.

In the page_load event i fill the dropdownlist with some database values. i.e.,

MIDL
if (!IsPostBack)
        {
//filling the dropdownlist.
}


now i select item from dropdownlist and press delete button and i show the following messagebox to the user

XML
string script = "<script type='text/javascript'>alert(' data is successfully deleted');</script>";
                    Page page = HttpContext.Current.CurrentHandler as Page;
                    if (!(page.ClientScript.IsClientScriptBlockRegistered("alert")))
                    {

                        page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script);
                    }

,it will successfully delete the record from the database

but it is still showing deleted item in the dropdownlist. what is the problem here.

i don't want the deleted item to be shown in the dropdownlist

please help me.

Thanks in Advance.
Regards,

Karan
Posted

Here is one solution for that


U just remove that item from dropdownlist

Write following code inside btnDelte_Click Event
After Displaying Ur Message


DropdownList1.Items.Remove(DropdownList1.SelectedValue);
 
Share this answer
 
Comments
karan joshua 8-Jun-11 6:45am    
thank u very much ....it works... My 5
Just try binding the DropDownList after deleting.

DropDownList1.DataBind();
 
Share this answer
 
Comments
S.M.Naresh 8-Jun-11 6:22am    
Yes rebinding the dropdown would do..
karan joshua 8-Jun-11 6:46am    
i tried this method but doesn't worked for me,... thank u very much for your response...
Yo have to call the dropdownlist bind function/method after deleting the record.

The binding code which you have written in page_load should be changed to a method/function.
Then call that method/function in the page_load and also after delete.
 
Share this answer
 
v2

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