how can i access the button field?
In the DetailsView DataBound event I've tried:
Dim AddtoCartButton As Button = CType(DetailsView1.Controls(0). Button)
but this doesn't work.
Since there is no ID field I can't access it directly with FindControl method.
Help?
Code:<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="false" AllowPaging="false" BorderWidth="0" BorderColor="white" DataSourceID="ObjectDataSourceItem"> <Fields> <asp:TemplateField> <ItemTemplate> <h1> <asp:Label ID="ProductName" runat="server" Text=' <%#Eval("Title")%>' /> </h1> <br /> <asp:Image ID="Image1" CssClass="photo-border" runat="server" ImageUrl='<%# "images/" + Eval("ImageUrl") %>' AlternateText='<%#Eval("ImageAltText")%>' Height="250px" Width="275px" /> <br /> <br /> <br /> <h2> Price: <asp:Label ID="PriceLabel" runat="server" Text='<%#Eval("Price","{0:C}") %>' /> </h2> <asp:Label ID="ProductID" runat="server" Text='<%#Eval("productid") %>' /> <br /> <asp:Label ID="DescriptionLabel" runat="server" Text='<%#Eval("Description") %>' /> <br /> <br /> <asp:Label ID="Color1Label" runat="server" Text="Color 1:" /> <asp:DropDownList ID="colors1" runat="server" > </asp:DropDownList><br /> <asp:Label ID="Color2Label" runat="server" Text="Color 2:" /> <asp:DropDownList ID="colors2" runat="server" > </asp:DropDownList> <br /><br /> In Stock: <asp:Label ID="InStockLabel" runat="server" Text='<%# IIf(Eval("InStock")= true, "Yes", "No") %>' /> <hr /> </ItemTemplate> </asp:TemplateField> <asp:ButtonField ButtonType="button" Text="Add to cart" CommandName="AddToCart" /> </Fields> </asp:DetailsView>




Reply With Quote