asp.net - How can I make the link in my GridView a single click? -


step 1:- click on more enter image description here

step 2:- click on add cart add item cart enter image description here

this gridview

<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 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 shoplist inner join shopdescription on shoplist.shopid = shopdescription.shopid">     </asp:sqldatasource> 

this code behind add cart link button

protected sub gvaddtocart_click(byval sender object, byval e system.eventargs)         if user.identity.name = ""             msgbox("you need login first before adding cart!", , "")             response.redirect("~/login.aspx", true)             exit sub         end if          dim scart = new cart         dim itemname, gvprice, offer label         dim userid, buyno, itemid string          itemid = request.querystring("itemid")         itemname = ctype(listview1.items(0).findcontrol("itemname"), label)         userid = user.identity.name          dim index integer = gridview1.editindex         gvprice = ctype(gridview1.rows(index).findcontrol("price"), label)         gvprice.text = ctype(gvprice.text, integer)         offer = ctype(gridview1.rows(index).findcontrol("offer"), label)          if scart.checkifitempresent(userid, itemid, gvprice.text, offer.text) = true             exit sub         end if          buyno = scart.findlatestbuyno(userid)         session("buyno") = buyno          session("buyno") = scart.addtocart(itemid, itemname.text, gvprice.text, offer.text, buyno, userid)     end sub 

so want remove step 1..how can this?

if remove more link..it stops working...please me.

i have click on more link to add cart link...i want add item cart in 1 click..with have ...i need 2 clicks.

when click on more goes edit mode..then when click on add cart(which in edit template)..it takes price , offer values edit template..if move "add cart" button itemtemplate...it cant access offer , price values. if move "add cart" button itemtemplate how know row being clicked?

by description "remove step 1", sounds want link/button field shown add cart time.

suggest creating buttonfield instead of itemtemplates , edititemtemplates. appears don't need editing capability, rather way access properties on row.

 <asp:gridview onrowcommand="gridview_rowcommand">       <asp:buttonfield buttontype="link"                        commandname="add"                        text="add cart"/>        <asp:boundfield datafield="itemname" headertext="item"/>       <asp:boundfield datafield="itemprice" headertext="your price"/>       <asp:boundfield datafield="shopname" headertext="shop name"/>       ..... etc. 

your code-behind need changed so:

  sub gridview_rowcommand(byval sender object, byval e gridviewcommandeventargs)      if e.commandname = "add"             dim index integer = convert.toint32(e.commandargument)       dim row gridviewrow = gridview1.rows(index)        dim itemname string = server.htmldecode(row.cells(1).text)        dim itemprice string = server.htmldecode(row.cells(2).text)        '...... etc       'all required business logic add cart.     end if    end sub 

Comments