继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

DataList中TextBox onfocus调用后台静态方法

ios开发零基础入门
关注TA
已关注
手记 265
粉丝 20
获赞 110


xxx.aspx:

5acf07330001405b00110016.jpgView 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:

5acf07330001405b00110016.jpgView 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();
    }

 

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP