Asp.net 如何使GridView中的链接只需单击一次?
第一步:-点击更多 第2步:-单击“添加到购物车”将项目添加到购物车 这是我的网格视图Asp.net 如何使GridView中的链接只需单击一次?,asp.net,Asp.net,第一步:-点击更多 第2步:-单击“添加到购物车”将项目添加到购物车 这是我的网格视图 <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
<asp:GridView ID="GridView1" runat="server"
AllowSorting="True"
AutoGenerateColumns="False"
CellPadding="4"
ForeColor="#333333"
GridLines="None"
Width="810px"
CssClass="gridview"
DataSourceID="SqlDataSource3" >
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">More...</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="GVAddToCart" runat="server" onclick="GVAddToCart_Click">Add to cart</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="itemName" SortExpression="itemName">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("itemName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="itemName" runat="server" Text='<%# Eval("itemName") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="price" SortExpression="price">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("price") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="price" runat="server" Text='<%# Eval("price") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="offer" SortExpression="offer">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("offer") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="offer" runat="server" Text='<%# Eval("offer") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="availability" SortExpression="availability">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("availability") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="availability" runat="server" Text='<%# Eval("availability") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="shopName" SortExpression="shopName">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("shopName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="shopName" runat="server" Text='<%# Eval("shopName") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="address" SortExpression="address">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("address") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="address" runat="server" Text='<%# Eval("address") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="email" SortExpression="email">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("email") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="email" runat="server" Text='<%# Eval("email") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="phone" SortExpression="phone">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("phone") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="phone" runat="server" Text='<%# Eval("phone") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:databaseConnectionString %>"
SelectCommand="SELECT shopList.itemName, shopList.offer, shopList.price, shopList.availability, shopDescription.shopName, shopDescription.address, shopDescription.email, shopDescription.phone FROM shopList INNER JOIN shopDescription ON shopList.shopID = shopDescription.shopID">
</asp:SqlDataSource>
所以我想做的是删除步骤1.我怎么做
如果我删除更多链接…它将停止工作…请帮助我
我必须单击更多链接才能获得“添加到购物车”链接…我想在一次单击中向购物车添加一个项目..用我现在拥有的…我需要两次单击
当我单击“更多”时,它将进入编辑模式。然后,当我单击“添加到购物车”(位于编辑模板中)时,它将从编辑模板中获取价格和优惠值。如果我将“添加到购物车”按钮移动到项目模板中
,它将无法访问优惠和价格值。如果我将“添加到购物车”按钮移动到ItemTemplate
中,我如何知道正在单击哪一行?根据您的描述“删除步骤1”,听起来您希望链接/按钮字段始终显示为“添加到购物车”
建议创建一个按钮字段
,而不是项目模板
和编辑项目模板
。看起来您不需要编辑功能,只需要访问行上的这些属性
<asp:GridView OnRowCommand="GridView_RowCommand">
<asp:ButtonField buttontype="Link"
commandname="Add"
text="Add to Cart"/>
<asp:BoundField datafield="itemName" headertext="Item"/>
<asp:BoundField datafield="itemPrice" headertext="Your Price"/>
<asp:BoundField datafield="shopName" headertext="Shop Name"/>
..... etc.
不..实际上我必须点击更多链接才能获得添加到购物车链接…我想一次点击将一个项目添加到购物车..用我现在拥有的…我需要两次点击。当我点击更多时,它进入编辑模式..然后当我点击添加到购物车(在编辑模板中)…它会从编辑模板中获取价格和报价值..如果我移动“添加到购物车”按钮进入ItemTemplate…它无法访问报价和价格值。如果我将“添加到购物车”按钮移动到ItemTemplate中,我如何知道正在单击哪一行???如果我将“添加到购物车”按钮移动到ItemTemplate中,如何使其工作?请帮助我…我尝试了很多次,但没有成功。
<asp:GridView OnRowCommand="GridView_RowCommand">
<asp:ButtonField buttontype="Link"
commandname="Add"
text="Add to Cart"/>
<asp:BoundField datafield="itemName" headertext="Item"/>
<asp:BoundField datafield="itemPrice" headertext="Your Price"/>
<asp:BoundField datafield="shopName" headertext="Shop Name"/>
..... etc.
Sub GridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Add" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(index)
Dim itemName As String = Server.HtmlDecode(row.Cells(1).Text)
Dim itemPrice As String = Server.HtmlDecode(row.Cells(2).Text)
'...... etc
'All required business logic to add to cart.
End If
End Sub