每次单击按钮时,gridview列中的值都会重复

时间:2016-06-09 17:58:43

标签: c# duplicates repeater

我在转发器中有一个嵌套的gridiview:

   <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SDSRepeaterCity" OnItemDataBound="Repeater1_ItemDataBound">
           <ItemTemplate>
               <table>
                   <tr>
                       <td ><label style="color:black; font-size:20px;"><%#Eval("nome_citta") %></label></td>
                       <td style="display:none;"><asp:Label ID="lblIdCity" runat="server" Text='<%#Eval("id_citta") %>' ></asp:Label></td>
                   </tr>
                   <tr>
                       <td colspan="2">
                           <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="False" 
                CssClass="Grid" 
                EmptyDataText="Nessun risultato corrispondono alla sua ricerca" 
                ShowHeaderWhenEmpty="True"  >
              <Columns>
                <asp:TemplateField>

            <ItemTemplate>
                <img alt = "" style="cursor: pointer" src="../../../Images/plus.png" />
                <asp:Panel ID="pnlOrders" runat="server" Style="display: none">
                    <asp:GridView ID="gvOrders"   runat="server"  AutoGenerateColumns="false" CssClass = "ChildGrid">
                        <Columns>
                          <asp:BoundField ItemStyle-Width="150px" DataField="TipoServizio"   HeaderText="TipoServizio" />
                            <asp:BoundField ItemStyle-Width="33%" DataField="Tipologia" HeaderText="Tipologia" />
                          <asp:TemplateField>
                              <HeaderTemplate>Prezzo di base</HeaderTemplate>
                              <ItemTemplate >

                                  <asp:TextBox ID="TBPrezzo" style="text-align:center;font-size:14px;" runat="server" Text=""></asp:TextBox>
                              </ItemTemplate>
                              <ItemStyle HorizontalAlign="Center" />
                          </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

                </asp:Panel>
            </ItemTemplate>
                    <HeaderStyle Width="150px" />
        </asp:TemplateField>


                <asp:BoundField DataField="tipo_macchina" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" HeaderText="AutoMezzo">
                  <ItemStyle HorizontalAlign="Left" />
                  </asp:BoundField>
     <asp:BoundField DataField="tipo_macchina" HeaderText="AutoMezzo">
                  <ItemStyle HorizontalAlign="Left" />
                  </asp:BoundField>

                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:Label ID="lblGvIdCity" runat="server" Text=""></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
              </Columns>

                                </asp:GridView>
                       </td>
                   </tr>
               </table>
           </ItemTemplate>
       </asp:Repeater> 

使用以下代码更新按钮:

   TraifRegBLL trigis = TraifRegBLL.Instance;

    string strConnString1 = "connexion";
    using (SqlConnection con = new SqlConnection(strConnString1))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            String id_aff = Session["id_affiliato"].ToString();
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "DELETE FROM TarifSMReg  WHERE id_affiliato= @Codice ";
            cmd.Parameters.AddWithValue("@Codice", id_aff);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
    //Add new inseriment

    for (int i = 0; i < Repeater1.Items.Count; i++)
    {
        GridView gvCustomers = Repeater1.Items[i].FindControl("gvCustomers") as GridView;

        for (int j = 0; j < gvCustomers.Rows.Count; j++)
        {
            Label lblGvIdCity = gvCustomers.Rows[j].FindControl("lblGvIdCity") as Label;
            GridView gvOrders = gvCustomers.Rows[j].FindControl("gvOrders") as GridView;
            for (int k = 0; k < gvOrders.Rows.Count; k++)
            {
                TextBox TBPrezzo = gvOrders.Rows[k].FindControl("TBPrezzo") as TextBox;
                if (String.IsNullOrEmpty(TBPrezzo.Text)==true) { TBPrezzo.Text = "0"; }
                if (Convert.ToDouble(TBPrezzo.Text) > 0)
                {
                    TarifSMReg t = new TarifSMReg();
                    t.id_citta = lblGvIdCity.Text;
                    t.id_affiliato = Session["id_affiliato"].ToString();
                    t.tipologia_macchina = gvCustomers.Rows[j].Cells[2].Text;
                    t.TipoServizio = gvOrders.Rows[k].Cells[0].Text;
                    t.Tipologia = gvOrders.Rows[k].Cells[1].Text;
                    t.PrezzoBaseRG = Convert.ToDouble(TBPrezzo.Text.Replace(",", "."));
                    trigis.addTarifReg(t);
                }


            }
        }
    }
如果我第一次插入价格,结果是

hereenter image description here

但是,如果我更新价格将重复像 thisenter image description here

任何人都可以解释我为什么吗?

谢谢

0 个答案:

没有答案