DataList中TextBox onfocus調(diào)用后臺void靜態(tài)方法及獲取相應(yīng)行數(shù)
昨天在某一論壇上看到的。Insus.NET嘗試做了一下,算是練習(xí)了。

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 "當(dāng)前行號為" + (e.Item.ItemIndex + 1).ToString();
}
private static string GetTextBox(DataListItemEventArgs e)
{
return "這是從靜態(tài)方法獲取值和當(dāng)前行索引值為:" + e.Item.ItemIndex.ToString();
}
相關(guān)文章
Asp.net Core中實現(xiàn)自定義身份認(rèn)證的示例代碼
這篇文章主要介紹了Asp.net Core中實現(xiàn)自定義身份認(rèn)證的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
asp.net下獲取遠(yuǎn)程網(wǎng)頁的內(nèi)容之二(downmoon原創(chuàng))
asp.net下獲取遠(yuǎn)程網(wǎng)頁的內(nèi)容之二(downmoon原創(chuàng))...2007-04-04
一天精通asp.net的學(xué)習(xí)經(jīng)驗小結(jié)
一天精通asp.net的學(xué)習(xí)經(jīng)驗小結(jié)2010-02-02
ASP.NET 2.0/3.5中直接操作Gridview控件插入新記錄
Gridview控件中并沒有提供像在FormView和DetailsView控件中那樣直接插入新記錄操作的支持。2008-11-11

