无为清净楼资源网 Design By www.qnjia.com

昨天在某一论坛上看到的。Insus.NET尝试做了一下,算是练习了。

DataList中TextBox onfocus调用后台void静态方法及获取相应行数

Insus.NET的测试演示:

DataList中TextBox onfocus调用后台void静态方法及获取相应行数

xxx.aspx: 
复制代码 代码如下:
<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:
复制代码 代码如下:
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();
}

标签:
DataList,TextBox,静态方法

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com