登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

学无止境

一点积累,与大家分享

 
 
 

日志

 
 

UpdatePanel with ASP.NET Repeater and Checkbox Aync Postback Example  

2010-06-30 13:05:08|  分类: .net技术 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
ASPX CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="UpdatePanelAnimation_test2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
     <asp:UpdatePanel runat="server" ID="udp_Lists" UpdateMode="Always">
<ContentTemplate>
    <asp:Repeater ID="rep_showings" runat="server">
        <HeaderTemplate>
        </HeaderTemplate>
        <ItemTemplate>
            <div class="div_assignment">
                <div class="div_assignment_text">
                    <asp:CheckBox runat="server" ID="chk_handle" AutoPostBack="true" OnCheckedChanged="chk_handle_Changed"   ToolTip='<%# Eval("Id") %>' Checked="False" />
                    <asp:LinkButton runat="server" ID="lnk_show_task" OnClick="lnk_show_task_Click" CommandArgument='<%# Eval("Id") %>' Text='<%# Eval("Title") %>'></asp:LinkButton>
                    </div> 
                   <asp:UpdatePanel  ID="UpdatePanel2" runat="server">
                             <ContentTemplate>
                               <asp:Label ID="Label1" runat="server"></asp:Label>
                             </ContentTemplate>
                  </asp:UpdatePanel>
              
            </div>
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
    </asp:Repeater>
</ContentTemplate>
<Triggers>
</Triggers>
  </asp:UpdatePanel>
  </form>
</body>
</html>

Behind Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UpdatePanelAnimation_test2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int size = 10;
            object[] objs = new object[size];
            for (int i = 0; i < size; i++)
            {
                objs[i] = new {Title = "title"+i, ID = "id"+i } ;
            }
            this.rep_showings.DataSource = objs;
            //new object[] { new { Title = "title", ID = "id" }, new { Title = "title1", ID = "id1" } };
            this.rep_showings.DataBind();
        }

    }
    public string GetContentFillerText()
    {
        return
            "ASP.NET AJAX is a free framework for building a new generation of richer, more interactive, highly personalized cross-browser web applications.  " +
            "This new web development technology from Microsoft integrates cross-browser client script libraries with the ASP.NET 2.0 server-based development framework.  " +
            "In addition, ASP.NET AJAX offers you the same type of development platform for client-based web pages that ASP.NET offers for server-based pages.  " +
            "And because ASP.NET AJAX is an extension of ASP.NET, it is fully integrated with server-based services. ASP.NET AJAX makes it possible to easily take advantage of AJAX techniques on the web and enables you to create ASP.NET pages with a rich, responsive UI and server communication.  " +
            "However, AJAX isn't just for ASP.NET.  " +
            "You can take advantage of the rich client framework to easily build client-centric web applications that integrate with any backend data provider and run on most modern browsers.  ";
    }

    protected void chk_handle_Changed(object source, EventArgs e)
    {
        Trace.Write("here");
        RepeaterItem ritem;
        CheckBox chkBox = (CheckBox)source;
        RepeaterItem repItem = (RepeaterItem)chkBox.NamingContainer;
        for (int i = 0; i < rep_showings.Items.Count; i++)
        {
            ritem = rep_showings.Items[i];
            if (repItem != ritem || (repItem == ritem&&!chkBox.Checked))
            {
                CheckBox chk = (CheckBox)ritem.FindControl("chk_handle");
                chk.Checked = false;
                UpdatePanel panel = (UpdatePanel)ritem.FindControl("UpdatePanel2");
                Label lblUpdate1 = (Label)panel.FindControl("Label1");
                lblUpdate1.Visible = false;
            }

        }
      
      
        repItem = rep_showings.Items[repItem.ItemIndex];

        UpdatePanel CurrentUpdatePanel;
        CurrentUpdatePanel = (UpdatePanel)repItem.FindControl("UpdatePanel2");
        Label lblUpdate = (Label)CurrentUpdatePanel.FindControl("Label1");
     
        if (chkBox.Checked == true)
        {
            lblUpdate.Visible = true;
            if (String.IsNullOrEmpty(lblUpdate.Text))
                lblUpdate.Text = GetContentFillerText();
        }

       
    }

    protected void lnk_show_task_Click(object source, EventArgs e)
    {
        Trace.Write("here 2");
    }

    protected void rep_showings_ItemCommand(object source, RepeaterCommandEventArgs e)
    { }

}
  评论这张
 
阅读(1362)| 评论(0)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018