protected void dlHead_ItemDataBound(object sender, DataListItemEventArgs e)
{ imgbtn += i.ToString();
if (e.Item.ItemType == ListItemType.Item)
{
ImageButton ibtn = (ImageButton)e.Item.FindControl("imgbtn1");
ibtn.Attributes.Add("onclick", "javascript:window.open('PerVip.aspx?UDM_Acc=" + ibtn.CommandArgument + "');");
}
}
<asp:DataList ID="dlHead1" CssClass="imgbtn" runat="server" OnItemDataBound="dlHead_ItemDataBound">
<ItemTemplate>
<asp:ImageButton ID="imgbtn1" runat="server" Height="50px" ImageUrl='<%# "Img_Vip\\"+Eval("head") %>'
CommandArgument='<%# Eval("UDM_Acc") %>' Width="50px" />
</ItemTemplate>
</asp:DataList>
结果 浏览器的解析代码居然是:
<input type="image" name="ctl00$cphcon3_1$dlHead1$ctl00$imgbtn1" id="ctl00_cphcon3_1_dlHead1_ctl00_imgbtn1" src="Img_Vip\8.gif" onclick="javascript:window.open('PerVip.aspx?UDM_Acc=70000');" style="height:50px;width:50px;border-width:0px;" />
</td>
</tr><tr>
<td>
<input type="image" name="ctl00$cphcon3_1$dlHead1$ctl01$imgbtn1" id="ctl00_cphcon3_1_dlHead1_ctl01_imgbtn1" src="Img_Vip\11.gif" style="height:50px;width:50px;border-width:0px;" />每格1条 onclick事件就不见了???
这是怎么回事?有什么解决方法吗???求救中!!!
{ imgbtn += i.ToString();
if (e.Item.ItemType == ListItemType.Item)
{
ImageButton ibtn = (ImageButton)e.Item.FindControl("imgbtn1");
ibtn.Attributes.Add("onclick", "javascript:window.open('PerVip.aspx?UDM_Acc=" + ibtn.CommandArgument + "');");
}
}
<asp:DataList ID="dlHead1" CssClass="imgbtn" runat="server" OnItemDataBound="dlHead_ItemDataBound">
<ItemTemplate>
<asp:ImageButton ID="imgbtn1" runat="server" Height="50px" ImageUrl='<%# "Img_Vip\\"+Eval("head") %>'
CommandArgument='<%# Eval("UDM_Acc") %>' Width="50px" />
</ItemTemplate>
</asp:DataList>
结果 浏览器的解析代码居然是:
<input type="image" name="ctl00$cphcon3_1$dlHead1$ctl00$imgbtn1" id="ctl00_cphcon3_1_dlHead1_ctl00_imgbtn1" src="Img_Vip\8.gif" onclick="javascript:window.open('PerVip.aspx?UDM_Acc=70000');" style="height:50px;width:50px;border-width:0px;" />
</td>
</tr><tr>
<td>
<input type="image" name="ctl00$cphcon3_1$dlHead1$ctl01$imgbtn1" id="ctl00_cphcon3_1_dlHead1_ctl01_imgbtn1" src="Img_Vip\11.gif" style="height:50px;width:50px;border-width:0px;" />每格1条 onclick事件就不见了???
这是怎么回事?有什么解决方法吗???求救中!!!
服务器控件生成一个唯一的 ClientID ,ClientID 通过将子控件的父控件的 UniqueID 值与控件的 ID 值连接生成,各个部分之间以下划线 _ 连接
<input type="image" name="ctl00$cphcon3_1$dlHead1$ctl00$imgbtn1" id="ctl00_cphcon3_1_dlHead1_ctl00_imgbtn1" src="Img_Vip\8.gif" onclick="javascript:window.open('PerVip.aspx?UDM_Acc=70000');" style="height:50px;width:50px;border-width:0px;" />
</td>
</tr><tr>
<td>
<input type="image" name="ctl00$cphcon3_1$dlHead1$ctl01$imgbtn1" id="ctl00_cphcon3_1_dlHead1_ctl01_imgbtn1" src="Img_Vip\11.gif" style="height:50px;width:50px;border-width:0px;" />
</td>
</tr><tr>
<td>
<input type="image" name="ctl00$cphcon3_1$dlHead1$ctl02$imgbtn1" id="ctl00_cphcon3_1_dlHead1_ctl02_imgbtn1" src="Img_Vip\9.gif" onclick="javascript:window.open('PerVip.aspx?UDM_Acc=8a8a8A');" style="height:50px;width:50px;border-width:0px;" />
ibtn.Attributes.Add("onclientclick", "javascript:window.open('PerVip.aspx?UDM_Acc=" + ibtn.CommandArgument + "');");
ibtn.Attributes.Add("onclientclick", "javascript:window.open('PerVip.aspx?UDM_Acc=" + ibtn.CommandArgument + "');");
能给个代码吗???
谢谢!!!!
if (e.Item.ItemType == ListItemType.Item||e.Item.ItemType == ListItemType.AlternatingItem)
{
ImageButton ibtn = (ImageButton)e.Item.FindControl("imgbtn1");
ibtn.Attributes.Add("onclick", "javascript:window.open('PerVip.aspx?UDM_Acc=" + ibtn.CommandArgument + "');");
}