Raul Juarez

Raul Juarez

  • NA
  • 43
  • 0

GRID VIEW Passing multiple pareneters to delete rows

Dec 10 2009 9:58 AM

Hello guys I have a Gridview populated with products at this moment am able to select each row (one or many) pass the product ID to lnkDeleteSelected_Click method iterate to the selected product ID and pass those values to another method "Product.Delete(int.Parse(selectedItems[i]));" as you can observe this method is receiving just one parameter. I need to fix the lnkDeleteSelected_Click to be able to pass ShoeNumber as a second parameter, both parameters need to be pass as integers. Any ideas would be appreciate it.
 
//ASP.NET CODE
               <ContentTemplate>
                <asp:GridView ID="grdProduct" runat="server" AutoGenerateColumns="False"
                BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
                CellPadding="2" ForeColor="Black" GridLines="None" AllowSorting="True"
                Font-Size="X-Small" Width="450" align="center" ShowFooter="True"
                       >
  <HeaderStyle BackColor="Tan" Font-Bold="True" HorizontalAlign="Left" Font-Size="X-Small" />
                <AlternatingRowStyle BackColor="PaleGoldenrod" />
                <rowstyle verticalalign = "top" />
                <editrowstyle backcolor = "lightgreen" />
                <Columns>
                    <asp:TemplateField HeaderText="">
                        <ItemTemplate>
                            <input type="checkbox" name="chkSelectedItems" value="<%# ((ProductSelected)Container.DataItem).ProductID.ToString() %>" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Shoe Nro&nbsp;">
                        <ItemTemplate>
                            <%# ((ProductSelected)Container.DataItem).ShoeNumber %>
                        </ItemTemplate>
                    </asp:TemplateField>                                 
                    <asp:TemplateField HeaderText="Gender&nbsp;&nbsp;" HeaderStyle-HorizontalAlign="left">
                        <ItemTemplate>
                            <%# ((ProductSelected)Container.DataItem).ProductGender %>
                        </ItemTemplate>
                    </asp:TemplateField>
                     
<asp:TemplateField HeaderText="Price">
                    <ItemTemplate>
                    <%# GetUnitPrice(decimal.Parse(Eval("ProductPrice").ToString())).ToString("N2") %>
                    </ItemTemplate>
                   
                     <FooterTemplate>
                     <div>Total:<%# GetTotal().ToString("N2") %></div>
                      <div><asp:LinkButton ID="lnkDeleteSelected" runat="server" Text="Delete Selected Items" OnClientClick="return confirm('Are you sure you want to delete the selected items?');" OnClick="lnkDeleteSelected_Click" /></div>
                     </FooterTemplate>
                  </asp:TemplateField>
                </Columns>
       </asp:GridView>
     </ContentTemplate>       
//END ASP.NET CODE
//CODE BEHIND FUNCTION TO DELETE A PRODUCT FROM GRIDVIEW
protected void lnkDeleteSelected_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.Form["chkSelectedItems"]))
            {
                string[] selectedItems = Request.Form["chkSelectedItems"].Split(',');
                for (int i = 0; i < selectedItems.Length; i++)
                {
                    try
                    {
                        Product.Delete(int.Parse(selectedItems[i]));
                    }
                    catch
                    {
                    }
                }
            }
        }
//END CODE BEHIND

Answers (1)