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 ();
}