手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >DataList中TextBox onfocus调用后台void静态方法及获取相应行数
DataList中TextBox onfocus调用后台void静态方法及获取相应行数
摘要:昨天在某一论坛上看到的。Insus.NET尝试做了一下,算是练习了。Insus.NET的测试演示:xxx.aspx:复制代码代码如下:物料编...

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

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

Insus.NET的测试演示:

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

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 onfocus调用后台void静态方法及获取相应行数】相关文章:

ASP.Net中数据展示控件的嵌套使用示例

ASP.NET技巧:同时对多个文件进行大量写操作对性能优化

ASP.net判断上传文件类型的三种有效方法

asp.net中导出excel数据的方法汇总

asp.net中使用cookie传递参数的方法

asp.net中List的使用方法

不能忽略c#中的using和as操作符的用处

asp.net中Repeater控件用法笔记

xenocode代码混淆加密的操作步骤

asp.net读取excel中的数据并绑定在gridview

精品推荐
分类导航