In DataList, TextBox onfocus calls the void static method in the background and obtains the corresponding number of rows.

Source: Internet
Author: User

I saw it on a forum yesterday. Insus. NET tried to do it. It is an exercise.

Test Demonstration of Insus. NET:

Xxx. aspx: 
Copy codeThe Code is as follows:
<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%">
Material Code <% # 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:
Copy codeThe Code is as follows:
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 "current row number is" + (e. Item. ItemIndex + 1). ToString ();
}
Private static string GetTextBox (DataListItemEventArgs e)
{
Return "this is the value obtained from the static method and the index value of the current row is:" + e. Item. ItemIndex. ToString ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.