zoukankan      html  css  js  c++  java
  • DataList中TextBox onfocus调用后台静态方法

    昨天在某一论坛上看到一帖,URL:http://topic.csdn.net/u/20111114/15/27b7810b-9892-49b7-b155-1604684069a3.html 。Insus.NET尝试做了一下,算是练习了。

    Insus.NET的测试演示:

    xxx.aspx:

    View Code
    <asp:DataList ID="dlItemGeneral" runat="server" CellPadding="0" CellSpacing="0" Width="100%"
                OnItemDataBound
    ="dlItemGeneral_ItemDataBound">
                <ItemTemplate>
                    <asp:Table ID="Table1" runat="server" CssClass="table">
                        <asp:TableRow>
                            <asp:TableCell CssClass="tableTemplateCell" Width="15%">
                                        物料编码 <%Eval("ItemCode"%>
                            </asp:TableCell>
                            <asp:TableCell CssClass="tableCell" Width="30%">
                                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            </asp:TableCell>
                            <asp:TableCell CssClass="tableCell" Width="55%">                                   
                            </asp:TableCell>
                        </asp:TableRow>
                    </asp:Table>
                </ItemTemplate>
            </asp:DataList>

    xxx.aspx.cs:

    View Code
     protected void dlItemGeneral_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (e.Item.FindControl("TextBox1") != null)
                {
                    TextBox textBox = e.Item.FindControl("TextBox1"as TextBox;
                    textBox.Attributes.Add("OnFocus""alert('" + GetRowNumber(e) + "'); this.value='" + GetTextBox(e) + "';");
                }
            }
        }
        private static string GetRowNumber(DataListItemEventArgs e)
        {
            return "当前行号为" + (e.Item.ItemIndex + 1).ToString();
        }

        private static string GetTextBox(DataListItemEventArgs e)
        {
            return "这是从静态方法获取值和当前行索引值为:" + e.Item.ItemIndex.ToString();
        }
  • 相关阅读:
    Libgdx之Music Sound 音效
    [Android]Activity的生命周期
    Android开发中无处不在的设计模式——动态代理模式
    Wireshark数据抓包分析——网络协议篇
    iOS-一个弹出菜单动画视图开源项目分享
    给Java开发人员的Play Framework(2.4)介绍 Part1:Play的优缺点以及适用场景
    mybatis自己学习的一些总结
    Cocos2d-x 源代码分析 : Scheduler(定时器) 源代码分析
    exe4j打包java应用程序
    删除sql server用户时报15138错误
  • 原文地址:https://www.cnblogs.com/insus/p/2249607.html
Copyright © 2011-2022 走看看