• <legend id='zuXIe'><style id='zuXIe'><dir id='zuXIe'><q id='zuXIe'></q></dir></style></legend>
  • <tfoot id='zuXIe'></tfoot>

    <small id='zuXIe'></small><noframes id='zuXIe'>

          <bdo id='zuXIe'></bdo><ul id='zuXIe'></ul>
      1. <i id='zuXIe'><tr id='zuXIe'><dt id='zuXIe'><q id='zuXIe'><span id='zuXIe'><b id='zuXIe'><form id='zuXIe'><ins id='zuXIe'></ins><ul id='zuXIe'></ul><sub id='zuXIe'></sub></form><legend id='zuXIe'></legend><bdo id='zuXIe'><pre id='zuXIe'><center id='zuXIe'></center></pre></bdo></b><th id='zuXIe'></th></span></q></dt></tr></i><div id='zuXIe'><tfoot id='zuXIe'></tfoot><dl id='zuXIe'><fieldset id='zuXIe'></fieldset></dl></div>

        ASP.net C# Gridview ButtonField onclick 事件

        时间:2023-06-05

        <small id='cfYEI'></small><noframes id='cfYEI'>

      2. <tfoot id='cfYEI'></tfoot><legend id='cfYEI'><style id='cfYEI'><dir id='cfYEI'><q id='cfYEI'></q></dir></style></legend>
          <i id='cfYEI'><tr id='cfYEI'><dt id='cfYEI'><q id='cfYEI'><span id='cfYEI'><b id='cfYEI'><form id='cfYEI'><ins id='cfYEI'></ins><ul id='cfYEI'></ul><sub id='cfYEI'></sub></form><legend id='cfYEI'></legend><bdo id='cfYEI'><pre id='cfYEI'><center id='cfYEI'></center></pre></bdo></b><th id='cfYEI'></th></span></q></dt></tr></i><div id='cfYEI'><tfoot id='cfYEI'></tfoot><dl id='cfYEI'><fieldset id='cfYEI'></fieldset></dl></div>
            <tbody id='cfYEI'></tbody>

          • <bdo id='cfYEI'></bdo><ul id='cfYEI'></ul>

                1. 本文介绍了ASP.net C# Gridview ButtonField onclick 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我为一个网上商店类型的项目编写了一个 ASP 代码.有一种方法可以将 ProductID 添加到 cookie 并在产品数量上加 1.另一种方法读取 cookie,将 cookie 转换为数据表并将其放入 gridview.这个gridview 基本上就是shoppingcart.aspx 页面.

                  I've written an ASP code for a webshop type project. There is a method that adds the ProductID to a cookie and adds 1 to the quantity of the product. Another method reads the cookie, transforms the cookie to a data table and puts it in a gridview. This gridview basically is the shoppingcart.aspx page.

                  我现在需要的是一种将按钮字段添加到该网格视图的方法,我可以在其中添加 ++ 按钮(如产品页面上的添加到购物车按钮),普通的 asp 按钮采用 onclick="methodname" 但gridview中的这些没有.

                  What i now need is a way to add a buttonfield to that gridview where i can add a ++ button (like the add to shopping cart button on a product page), normal asp buttons take a onclick="methodname" but these in the gridview don't.

                  add1ToShoppingCart(string productId)
                  {[...]shoppingCartCookie[productId] = (amount + 1).ToString();}
                  

                  这是我用于所有 ++ 按钮的代码.它需要 button.id (buttonID=productID).所以我需要一种方法让所有按钮都是相同的图像,但是 buttonID 必须数据绑定到 productID 以便它可以以某种方式执行该方法(使用某种 onclick="").

                  That is the code I use for all the ++ buttons. It takes the button.id (buttonID=productID). So I need a way to have all the buttons be the same image, but the buttonID has to be databound to the productID so it can somehow execute that method (with some sort of onclick="").

                  在过去的几个小时里,我一直在寻找和搜索,但我似乎找不到任何东西.过去我在stackoverflow上找到了很多答案,所以我希望这里有人可以提供帮助.

                  I've looked and googled for the past couple hours but I cant seem to find anything. In the past I found a lot of answers on stackoverflow so I hoped somebody here could help.

                  提前致谢.

                  推荐答案

                  你可以使用模板字段:

                                       <asp:TemplateField ItemStyle-Width="33px" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                                              ShowHeader="false" HeaderStyle-Height="40px">
                                              <ItemTemplate>
                                                  <asp:ImageButton ID="btnAddToCard" runat="server" ImageUrl="~/Images/btnAddToCard.png" CausesValidation="false"
                                                      CommandName="AddToCard" CommandArgument='<%# Eval("ID") %>'
                                                      />
                                              </ItemTemplate>
                                              <HeaderStyle Height="40px"></HeaderStyle>
                                              <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="33px"></ItemStyle>
                                          </asp:TemplateField>
                  

                  并在您背后的 C# 代码中创建 gridview 的以下事件并执行您想要的操作:

                  and in your C# code behind you create the following event of your gridview and do what you want :

                   protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
                      {
                          if (e.CommandName == "AddToCard")
                          {
                             //Write code to add to card
                          }
                     }
                  

                  GV 是我的 GridView 的 ID!

                  GV is the ID of my GridView !

                  这篇关于ASP.net C# Gridview ButtonField onclick 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将 OnClick 事件添加到 ASP.NET 控件 下一篇:从函数调用按钮 OnClick

                  相关文章

                  最新文章

                      <small id='BmKPn'></small><noframes id='BmKPn'>

                        <bdo id='BmKPn'></bdo><ul id='BmKPn'></ul>

                      <tfoot id='BmKPn'></tfoot>
                    1. <i id='BmKPn'><tr id='BmKPn'><dt id='BmKPn'><q id='BmKPn'><span id='BmKPn'><b id='BmKPn'><form id='BmKPn'><ins id='BmKPn'></ins><ul id='BmKPn'></ul><sub id='BmKPn'></sub></form><legend id='BmKPn'></legend><bdo id='BmKPn'><pre id='BmKPn'><center id='BmKPn'></center></pre></bdo></b><th id='BmKPn'></th></span></q></dt></tr></i><div id='BmKPn'><tfoot id='BmKPn'></tfoot><dl id='BmKPn'><fieldset id='BmKPn'></fieldset></dl></div>
                    2. <legend id='BmKPn'><style id='BmKPn'><dir id='BmKPn'><q id='BmKPn'></q></dir></style></legend>