DataList中TextBox onfocus調用后臺void靜態(tài)方法及獲取相應行數(shù)
昨天在某一論壇上看到的。Insus.NET嘗試做了一下,算是練習了。
Insus.NET的測試演示:
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 "這是從靜態(tài)方法獲取值和當前行索引值為:" + e.Item.ItemIndex.ToString();
}
相關文章
asp.net Linq To Xml上手Descendants、Elements遍歷節(jié)點
C#3.0 Vs2008 RTM 本文介紹如何使用 Descendants、Elements快速遍歷XML節(jié)點2009-07-07常用的在數(shù)據(jù)庫中建立無限級樹形菜單的asp.net代碼
經(jīng)常在項目中遇到建立無限級樹形菜單展示的效果,這里簡單地做了一個,基本后臺代碼如下2008-09-09ASP.NET網(wǎng)站偽靜態(tài)下使用中文URL的方法
中文URL是在URL中直接使用漢字,它的好處是可以使用鏈接地址看起來非常直觀易懂,偽靜態(tài)的規(guī)則,是在web.config文件中定義的2014-08-08ASP.NET 連接ACCESS數(shù)據(jù)庫的簡單方法
一段非常簡單的連接ACCESS數(shù)據(jù)庫的實例代碼,有需要的朋友可以參考一下2013-07-07