使对象可见和不可见 [英] Make object visible and invisible
问题描述
有没有办法可以在不刷新整个页面的情况下显示标签?或者不使用autopostback ='true"
Is there a way that I could display the lables without refreshing the whole page? Or not use autopostback='true"
html
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < asp:CheckBoxList ID =" chkDropAdd" RUNAT = QUOT;服务器"的AutoPostBack = QUOT;真"
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; onselectedindexchanged =" chkDropAdd_SelectedIndexChanged"
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; RepeatDirection = QUOT;水平" Width =" 221px">
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < asp:ListItem Value =" Drop">删除课程< / asp:ListItem>
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < asp:ListItem Value =" Add">添加课程< / asp:ListItem>
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < / asp:CheckBoxList>
<asp:CheckBoxList ID="chkDropAdd" runat="server" AutoPostBack="true"
onselectedindexchanged="chkDropAdd_SelectedIndexChanged"
RepeatDirection="Horizontal" Width="221px">
<asp:ListItem Value="Drop">Drop a Course</asp:ListItem>
<asp:ListItem Value="Add">Add a Course</asp:ListItem>
</asp:CheckBoxList>
C#
protected void chkDropAdd_SelectedIndexChanged(object sender,EventArgs e )
$
{
foreach(chkDropAdd.Items中的System.Web.UI.WebControls.ListItem oItem)
{
if(oItem.Selected)//如果您只想选择
{
if(oItem.Value ==" Drop")
&NBSP;&NBSP; {
Label6.Visible = true;
&NBSP; }¥b $ b if(oItem.Value ==" Add")
&NBSP;&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; Label7.Visible = true;
}
}
//否则获取所有项目
否则为
{
if(oItem.Value ==" Drop")
&NBSP;&NBSP;&NBSP; {
Label6.Visible = false;
}
if(oItem.Value ==" Add")
&NBSP;&NBSP;&NBSP; {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; Label7.Visible = false;
}
protected void chkDropAdd_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (System.Web.UI.WebControls.ListItem oItem in chkDropAdd.Items)
{
if (oItem.Selected) // if you want only selected
{
if (oItem.Value == "Drop")
{
Label6.Visible = true;
}
if (oItem.Value == "Add")
{
Label7.Visible = true;
}
}
// otherwise get for all items
else
{
if (oItem.Value == "Drop")
{
Label6.Visible = false;
}
if (oItem.Value == "Add")
{
Label7.Visible = false;
}
推荐答案
将AJAX用于ASP.NET应用程序。这是完美的。在这里找到Ajax控件工具包 - >
http://www.asp.net/ajax
Use AJAX for your ASP.NET application. It is perfect for this. Find the Ajax Control Toolkit Here -> http://www.asp.net/ajax
这篇关于使对象可见和不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!