昨天在某一論壇上看到的。Insus.NET嘗試做了一下,算是練習了。
Insus.NET的測試演示:
xxx.aspx: 復制代碼 代碼如下:
<asp:DataList runat="server" CellPadding="0" CellSpacing="0"
OnItemDataBound="dlItemGeneral_ItemDataBound">
<ItemTemplate>
<asp:Table runat="server" CssClass="table">
<asp:TableRow>
<asp:TableCell CssClass="tableTemplateCell">
物料編碼 <%# Eval("ItemCode") %>
</asp:TableCell>
<asp:TableCell CssClass="tableCell">
<asp:TextBox runat="server"></asp:TextBox>
</asp:TableCell>
<asp:TableCell CssClass="tableCell">
</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();
}
新聞熱點
疑難解答
圖片精選