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事件就不见了???
这是怎么回事?有什么解决方法吗???求救中!!!

解决方案 »

  1.   

    服务器端控件在页面显示为html元素
    服务器控件生成一个唯一的 ClientID ,ClientID 通过将子控件的父控件的 UniqueID 值与控件的 ID 值连接生成,各个部分之间以下划线 _ 连接
      

  2.   

    这个我知道,你看第三段代码onclick事件不见了一个!!!!这个是重点!!!
      

  3.   

    中间代码的onclick事件 不见啦  谁能帮帮忙 帮我找回来啊!!!!
    <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;" /> 
      

  4.   

    你的意思是这样写?
    ibtn.Attributes.Add("onclientclick", "javascript:window.open('PerVip.aspx?UDM_Acc=" + ibtn.CommandArgument + "');");
      

  5.   

    我发现这样不行啊
    ibtn.Attributes.Add("onclientclick", "javascript:window.open('PerVip.aspx?UDM_Acc=" + ibtn.CommandArgument + "');");
    能给个代码吗???
    谢谢!!!!
      

  6.   

    判断条件不对
    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 + "');");
                }
      

  7.   

    就是啊,你的判断条件不对啊,还要加个是不是AlternatingTemplate类型的啊