Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi
I have a panel where there is a repeater with one textbox and a label.

When you insert a number in textbox and click on update button it will count all the value from the text box and show the calculated number in a label.

And when the calculated number is 7 then you can not insert any numbers in the textbox.

I have try this:
I dont know what i could do when the number is reach 7.


C#
<asp:Panel ID="Panel_visfrugt" runat="server">
        <table border="1">
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [frugt]"></asp:SqlDataSource>
            <tr>
                <td>Antal</td>
                <td><asp:Label ID="Label1" runat="server" Text=""></asp:Label></td>
            </tr>
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand">
                <ItemTemplate>

            
            <tr>
                <td><%#Eval("frugt_navn") %></td>
                <td><asp:TextBox ID="txtbox1" runat="server" Width="30"></asp:TextBox></td>
            </tr>
            
    </ItemTemplate>
            </asp:Repeater>
        </table>
    </asp:Panel>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />



C#
  protected void Page_Load(object sender, EventArgs e)
    {
       
        Panel_visfrugt.Visible = true;
        
       
    }


protected void Button1_Click1(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in Repeater1.Items)
        {
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                TextBox Textbox_antal = item.FindControl("txtbox1") as TextBox;
                int antal = 0;

                int i = int.Parse(Textbox_antal.Text) + int.Parse(Textbox_antal.Text) + int.Parse(Textbox_antal.Text) + int.Parse(Textbox_antal.Text) + int.Parse(Textbox_antal.Text) + int.Parse(Textbox_antal.Text) + int.Parse(Textbox_antal.Text) + int.Parse(Textbox_antal.Text);

                if (antal != 7)
                {

                    Label1.Text = "Nu er der 7";
                
                }
               
                else
                {
                    Label1.Text = "Der er over 8 nu";
                }
               



            }

        } 
       
    }




Tina
Posted
Updated 6-Oct-13 2:53am
v3
Comments
JoCodes 5-Oct-13 13:53pm    
please elaborate what you want .. have you tried anything so far??
Pradeep Shukla 5-Oct-13 15:20pm    
You need to re-define \ explain your question properly...
tina_overgaard 6-Oct-13 7:58am    
I have updated my question

1 solution

Hi,
in this case you need to define a global variable to store the value on each time button clicked. try like this:
C#
private int Value = 0;
   protected void Page_Load(object sender, EventArgs e)
   {
       Panel_visfrugt.Visible = true;
   }

   protected void Button1_Click1(object sender, EventArgs e)
   {
       foreach (RepeaterItem item in Repeater1.Items)
       {
           if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
           {
               TextBox Textbox_antal = item.FindControl("txtbox1") as TextBox;

               Value = Convert.ToInt32(Value + int.Parse(Textbox_antal.Text));

               if (Value != 7)
               {
                   Label1.Text = "Nu er der 7";
               }
               else
               {
                   Label1.Text = "Der er over 8 nu";
               }
           }
       }
   }
 
Share this answer
 
Comments
tina_overgaard 8-Oct-13 3:51am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900