GridView图像按钮错误 [英] GridView Image Button error
问题描述
< asp:GridView ID =GridView1runat =serverAutoGenerateColumns =false
BackColor =WhiteBorderColor =#DEDFDEBorderStyle =无BorderWidth =1px
CellPadding =4ForeColor =BlackGridLines =Vertical
onselectedindexchanged =GridView1_SelectedIndexChanged>
< alternatingrowstyle backcolor =White>
< footerstyle backcolor =#CCCC99>
< HeaderStyle BackColor =#6B696B Font-Bold =TrueForeColor =White/>
< pagerstyle backcolor =#F7F7DEforecolor =Blackhorizontalalign =Right>
< rowstyle backcolor =#F7F7DE>
< SelectedRowStyle BackColor =#CE5D5AFont-Bold =TrueForeColor =White/>
< sortedascendingcellstyle backcolor =#FBFBF2>
< sortedascendingheaderstyle backcolor =#848384>
< sorteddescend ingcellstyle backcolor =#EAEAD3>
< sorteddescendingheaderstyle backcolor =#575357>
< columns> < asp:TemplateField HeaderText =Picture>
< itemtemplate>
< asp:Image ID =imgrunat =serverCssClass = cover-100 popupImageUrl ='<%#Eval(picture)%>'Height =100Weight =100/>
< asp:TemplateField HeaderText =产品代码>
< itemtemplate>
< asp:Label ID =lblrunat =serverText ='<%#Eval(productCode)%>'>
< asp:TemplateField HeaderText =产品名称>
< itemtemplate>
< ; asp:Label ID =lblrunat =serverText ='<%#Eval(productName)%>'>
< br $>
< asp:TemplateField HeaderText =Category>
< itemtemplate>
< asp:Label ID =lblrunat =serverText ='<%#Eval(category)%>'>
$ / b $ b
< asp:TemplateField HeaderText =性别>
< itemtemplate>
< asp:Label ID =lblrunat =serverText ='<%#Eval(gender)%>'>
< asp:TemplateField HeaderText =插入购物车>
< itemtemplate> ;
< asp:ImageButton ID =ImageButton2runat =serverImageUrl =〜/ Image / shopping-cart-insert-icon.pngHeight =100Width =100 />
最后一列图像按钮无法正常运行。错误消息显示:找到具有相同IDlbl的多个控件。 FindControl要求控件具有唯一ID。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="Vertical"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<alternatingrowstyle backcolor="White">
<footerstyle backcolor="#CCCC99">
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="#F7F7DE" forecolor="Black" horizontalalign="Right">
<rowstyle backcolor="#F7F7DE">
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#FBFBF2">
<sortedascendingheaderstyle backcolor="#848384">
<sorteddescendingcellstyle backcolor="#EAEAD3">
<sorteddescendingheaderstyle backcolor="#575357">
<columns> <asp:TemplateField HeaderText = "Picture">
<itemtemplate>
<asp:Image ID="img" runat="server" CssClass="cover-100 popup" ImageUrl='<%#Eval("picture") %>' Height="100" Weight="100" />
<asp:TemplateField HeaderText = "Product Code">
<itemtemplate>
<asp:Label ID="lbl" runat="server" Text='<%#Eval("productCode") %>'>
<asp:TemplateField HeaderText = "Product Name">
<itemtemplate>
<asp:Label ID="lbl" runat="server" Text='<%#Eval("productName") %>'>
<asp:TemplateField HeaderText = "Category">
<itemtemplate>
<asp:Label ID="lbl" runat="server" Text='<%#Eval("category") %>'>
<asp:TemplateField HeaderText = "Gender">
<itemtemplate>
<asp:Label ID="lbl" runat="server" Text='<%#Eval("gender") %>'>
<asp:TemplateField HeaderText = "Insert To Shopping Cart">
<itemtemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/Image/shopping-cart-insert-icon.png" Height="100" Width="100" />
The last Columns Image button cannot run correctly. The errors message show that: Multiple controls with the same ID 'lbl' were found. FindControl requires that controls have unique IDs.
推荐答案
<asp:Label ID="lbl" runat="server" Text='<%#Eval("productName") %>'>
<asp:TemplateField HeaderText = "Category">
<asp:Label ID="lbl" runat="server" Text='<%#Eval("category") %>'>
<asp:TemplateField HeaderText = "Gender">
<asp:Label ID="lbl" runat="server" Text='<%#Eval("gender") %>'>
代码中的很多标签都有相同的ID。将其标签更改为唯一ID, FindControl
应该有效。
这篇关于GridView图像按钮错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!