We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

delete selective item from dropdown list from database using c# in asp.net

Need to delete the selected item from the dropdown from the database with the button click.Also when user clicks the delete button i need to show the alert or confirm dialog box for confirmatiuon that user realy want to delete that item....plz help me ...

2
Contributors
3
Replies
1 Day
Discussion Span
3 Years Ago
Last Updated
4
Views
rohitmanhas_12
Light Poster
25 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

i want to fetch data in a DropDownList from Sql server and delete the selected data from dropdownlist...

rohitmanhas_12
Light Poster
25 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Well did you write any code yet? If I understand you right, you want to populate a dropdownlist from a database. Then you want to remove the selected item from the dropdownlist on a button click. You also want a dialog box to show before the removal of the selected item.

First look at databinding for your dropdownlist. Another thing if you are binding your dropdownlist in the page_load event make sure you put it in a if (!IsPostBack). This way each time you do a postback deleting a item from the dropdownlist it will not repopulate the list. So write some code and I or someone else will surely help.

Freon22
Light Poster
42 posts since Feb 2010
Reputation Points: 12
Solved Threads: 6
Skill Endorsements: 0

I can't sleep so I will do some of this for you. First make your dropdownlist add a button and add a call to a javascript fuction.

<asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <br /><br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return wait();" onclick="Button1_Click" />

Here is a quit javascript comfirm.

<script type="text/javascript">
    
      function wait()
      {
        if (confirm("Are you sure you want to delete this from the dropdownlist?") == true)
        return true;
        else
        return false;
      }
    
    </script>

Now lets make a generic list in the page load, you would want to load your droplistlist from your database.

using System.Collections.Generic;

public partial class GenericList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<string> myList = new List<string>();
            myList.Add("Item One");
            myList.Add("Item Two");
            myList.Add("Item Three");
            myList.Add("Item Four");
            DropDownList1.DataSource = myList;            
            DropDownList1.DataBind();
        }
    }

Now lets do the button click event.

protected void Button1_Click(object sender, EventArgs e)
    {
        DropDownList1.Items.Remove(DropDownList1.SelectedItem);
    }

There you go I don't think I forgot anything but like I said above you would fill your genericlist from your database then bind it to your dropdownlist. The idea is the same...

Freon22
Light Poster
42 posts since Feb 2010
Reputation Points: 12
Solved Threads: 6
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0645 seconds using 2.67MB