- VB.NET code
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound Dim textbox As TextBox = New TextBox() textbox = CType(e.Item.FindControl("textbox3"), TextBox) textbox.Text = "注意:" + textbox.Text End Sub
找不到控件,同样的代码在
- VB.NET code
Protected Sub DataList1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.UpdateCommand Dim textbox As TextBox = CType(e.Item.FindControl("textbox3"), TextBox) textbox.Text = "注意:" + textbox.TextEnd Sub
可以找到,为什么?有什么办法可以在DataList1_ItemDataBound事件中找到控件,我想在编辑模板中对其中的textbox3控件中的邦定数据进行一些初始化的修改,怎么做?请指教,谢谢
------解决方案--------------------------------------------------------
DataList1_ItemDataBound中找到并修改textbox3
------解决方案--------------------------------------------------------
第一段代码的:
Dim textbox As TextBox = New TextBox()
textbox = CType(e.Item.FindControl("textbox3"), TextBox)
改成: Dim textbox As TextBox = CType(e.Item.FindControl("textbox3"), TextBox)
试试
------解决方案--------------------------------------------------------
你要先判断e的ItemType
------解决方案--------------------------------------------------------
在DataList1_ItemDataBound事件中加入
if(e.item.itemType==ListItemType.Item||e.item.itemType==ListItemType.anternila)
{
//你的代码
}
哪个交替项的参数,不记的了