|
-
Oct 3rd, 2007, 10:49 PM
#1
Thread Starter
Fanatic Member
how to access ButtonField in DetailsView?
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>
-
Oct 6th, 2007, 01:42 PM
#2
Re: how to access ButtonField in DetailsView?
The ButtonField most likely contains a button itself, so you may need to CType to ButtonField, then get the control(0) out of it instead.
Try this, step through your code and when you get to
Dim AddtoCartButton As Button = CType(DetailsView1.Controls(0). Button)
Do a quickwatch on DetailsView1.Controls(0).
Most likely it's something from your ItemTemplate. Increase the number till you get something related to your buttonfield.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|