asp.net 2.0中的下拉列表问题 [英] drop down list problem in asp.net 2.0

查看:63
本文介绍了asp.net 2.0中的下拉列表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#,asp.net 2.0,Server 2005和Visual Studio 2005

任何人都可以在asp.net中解决以下下拉列表问题.

在page_load事件中,我用一些数据库值填充了下拉列表.即

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.,

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



现在,我从下拉列表中选择项目,然后按Delete键,并向用户显示以下消息框



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

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


,它将成功从数据库中删除记录

但它仍在下拉列表中显示已删除的项目.这是什么问题.

我不希望已删除的项目显示在下拉列表中

请帮帮我.

在此先感谢.
问候,

Karan


,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

推荐答案

这是解决该问题的一种方法


您只需从下拉列表中删除该项目

在btnDelte_Click事件中编写以下代码
显示Ur消息后


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


删除后只需尝试绑定DropDownList.

Just try binding the DropDownList after deleting.

DropDownList1.DataBind();


您必须在删除记录后调用dropdownlist绑定函数/方法.

您在page_load中编写的绑定代码应更改为方法/函数.
然后在page_load中以及在删除后调用该方法/函数.
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.


这篇关于asp.net 2.0中的下拉列表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆