Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Расчет при нажатии на кнопку. В расчет включить значение текста кнопки / 8 сообщений из 8, страница 1 из 1
23.12.2012, 22:33
    #38089980
REDD13
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
Здраствуйте! Помогите сделать так чтобы при нажатии на кнопку значение -число, которое находится на этой кнопке(данные берутся из базы данных) это значение вставлялось бы в формулу например такую 100+x , где x это значение взятое с кнопки результат должен выводиться на текстбоксе.

Код проги:


Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace Modul1
{
    public partial class About : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Предоставление прав доступа.
            String AlloyQuery =
            "SELECT id_control " +
            "FROM Access_rights WHERE id_user = " + Convert.ToInt16(Session["id_user"]) + ";";
            SqlConnection SelConnect =
                new SqlConnection("Data Source=(local)\\SQLEXPRESS;Initial Catalog=Alloys_db;" +
                    "Integrated Security=False; Pooling=False; User ID=sa;Password=' '");
            SqlCommand SelCommand = new SqlCommand(AlloyQuery.ToString(), SelConnect); //Создаём команду (запрос, соединение)
            SelConnect.Open();
            SqlDataReader AddReader = SelCommand.ExecuteReader();
            while (AddReader.Read())
            {
                if (AddReader["id_control"].ToString() == "AdmPanel1") { AdmPanel1.Visible = true; }
                if (AddReader["id_control"].ToString() == "AdmPanel2") { AdmPanel2.Visible = true; }
                if (AddReader["id_control"].ToString() == "AdmPanel3") { AdmPanel3.Visible = true; }
            }
            AddReader.Close();
            SelConnect.Close();
     
            //Создаём массив ссылок-кнопок для сплавов.
            LinkButton[] Alloy_buttons = new LinkButton[100];
           int i = 0;
            TableRow rw = new TableRow();
            AlloyQuery =
                "SELECT id_alloy, alloy_mark " +
                "FROM Alloys ORDER BY alloy_mark ASC;";
            SelCommand = new SqlCommand(AlloyQuery.ToString(), SelConnect); //Создаём команду (запрос, соединение)
            SelConnect.Open();
            AddReader = SelCommand.ExecuteReader();
            while (AddReader.Read())
            {
                Literal Lit1 = new Literal();
                Lit1.Text = "<br/>";
                Alloy_buttons[i] = new LinkButton();
                Alloy_buttons[i].Text = AddReader["alloy_mark"].ToString();
                Alloy_buttons[i].Click += new System.EventHandler(AButton_Click);
                Alloy_buttons[i].ID = "A0Button" + AddReader["id_alloy"].ToString(); //Записываем id сплава в button.ID.
                Alloy_buttons[i].PostBackUrl = "~/About.aspx";
                if (i % 4 == 0) { rw = new TableRow(); }
                if ((i + 1) % 8 == 0) { rw.BackColor = System.Drawing.Color.FromName("#A2CD5A"); }
                else { rw.BackColor = System.Drawing.Color.FromName("#BCEE68"); };
                TableCell cel = new TableCell();
                cel.Controls.Add(Alloy_buttons[i]);
                i++;
                rw.Cells.Add(cel);
                Table1.Rows.Add(rw);
            }
            AddReader.Close();
 
            SelConnect.Close();
 
            
 
        }
        //Переход на страницу сплава.
        void AButton_Click(object sender, EventArgs e)
        {
            LinkButton[] Alloy_buttons1 = new LinkButton[100]; //Верхний процент хим. состава
            LinkButton[] Alloy_buttons2 = new LinkButton[100]; //Нижний процент хим. состава
            
 
            //cоздаём таблицу с химическими элементами:
 
            TableCell cel = new TableCell();//столбец
            int i = 0;
            int n = 0; //счётчик строк
            TableRow rw = new TableRow();
            rw.Height = 50;
            rw.BackColor = System.Drawing.Color.FromName("#A2CD5A");
            for (int j = 0; j < 2; j++)
            {
                cel = new TableCell();
                cel.Text = "Элемент";
                cel.Width = Unit.Percentage(10);
                rw.Cells.Add(cel);
                cel = new TableCell();
                cel.Text = "от, %";
                cel.Width = Unit.Percentage(10);
                rw.Cells.Add(cel);
                cel = new TableCell();
                cel.Text = "до, %";
                cel.Width = Unit.Percentage(10);
                rw.Cells.Add(cel);
                
 
            }
            Table2.Rows.Add(rw);
            rw = new TableRow();
 
            String AlloyQuery =
 
                         "SELECT id_element, el_notation " +
                         "FROM Chemical_el ORDER BY el_notation ASC;";
            SqlConnection SelConnect =
             new SqlConnection("Data Source=(local)\\SQLExpress;Initial Catalog=Alloys_db;" +
                     "Integrated Security=False; Pooling=False; User ID=sa;Password=' '");
            SqlCommand SelCommand = new SqlCommand(AlloyQuery.ToString(), SelConnect); //Создаём команду (запрос, соединение)
            SelConnect.Open();
            SqlDataReader AddReader = SelCommand.ExecuteReader();
 
 
 
            while (AddReader.Read())
            {
                //Элементы
                if (n % 2 == 0) { rw = new TableRow(); }
                cel = new TableCell();
                cel.Text = AddReader["el_notation"].ToString();
                cel.Width = Unit.Percentage(10);
                cel.BackColor = System.Drawing.Color.FromName("#BCEE68");
                if (AddReader["el_notation"].ToString() == "Прочие")
                {
                    cel.Text += " примеси";
                }
                rw.Cells.Add(cel);
                //Верхний процент
                cel = new TableCell();
                Alloy_buttons1[i] = new LinkButton();
                Alloy_buttons1[i].ID = "ABox1" + AddReader["id_element"].ToString();
                Alloy_buttons1[i].Click += new System.EventHandler(QButton_Click);//при нажатии на эту кнопку значение этой кнопки должно попадать в формулу 
              
                cel.BackColor = System.Drawing.Color.FromName("#00FF00");
                Alloy_buttons1[i].Width = Unit.Percentage(95);
 
                cel.Controls.Add(Alloy_buttons1[i]);
                cel.Width = Unit.Percentage(10);
                rw.Cells.Add(cel);
                //Нижний процент
                cel = new TableCell();
                Alloy_buttons2[i] = new LinkButton();
                Alloy_buttons2[i].ID = "ABox1" + AddReader["id_element"].ToString();
                Alloy_buttons2[i].Click += new System.EventHandler(QButton_Click);//при нажатии на эту кнопку значение этой кнопки должно попадать в формулу 
                cel.BackColor = System.Drawing.Color.FromName("#00FF00");
                Alloy_buttons2[i].Width = Unit.Percentage(95);
                
                cel.Controls.Add(Alloy_buttons2[i]);
                cel.Width = Unit.Percentage(10);
                rw.Cells.Add(cel);
 
                Table2.Rows.Add(rw);
                i++;
                n++;
            }
            AddReader.Close();
            SelConnect.Close();
 
            //Заполнение значениями для хим. состава.
            for (int j = 0; j < i; j++)
            {
                AlloyQuery =
                    "SELECT max_percent, min_percent FROM Analysis WHERE id_element = " + Alloy_buttons1[j].ID.Substring(5) + ";";
                SelCommand = new SqlCommand(AlloyQuery.ToString(), SelConnect);
                SelConnect.Open();
                AddReader = SelCommand.ExecuteReader();
                if (AddReader.Read())
                {
                    Alloy_buttons1[j].Text = AddReader["min_percent"].ToString();
                    Alloy_buttons2[j].Text = AddReader["max_percent"].ToString();
 
                }
                AddReader.Close();
                SelConnect.Close();
            }
        }
 
 
 
                       
 
                                           
 
             void QButton_Click(object sender, EventArgs e)
        {
            здесь нужно сделать рассчет
                  
 
                     100+x
        }
          
                    
    
        
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            AdmPanel1.Visible = false;
            AdmPanel2.Visible = false;
            Session["id_user"] = null;
            AdmPanel3.Visible = false;
        }
        
 
        //==========>>
 
        
    }
}
...
Рейтинг: 0 / 0
23.12.2012, 22:38
    #38089984
Изопропил
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
http://govnokod.ru - сюда постить
...
Рейтинг: 0 / 0
23.12.2012, 22:43
    #38089990
REDD13
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
Изопропил,

если ты не знаешь как это сделать , так лучше вообще молчи просят помочь , а не шутки шутить...
...
Рейтинг: 0 / 0
24.12.2012, 10:50
    #38090299
МСУ
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
REDD13Изопропил, если ты не знаешь как это сделать , так лучше вообще молчи просят помочь , а не шутки шутить...
Зависит не от знания или незнания, как "это сделать". Зависит от желания ковыряться в твоем гавне (по-другому никак не назовешь твой код, прости), к тому же абсолютно не форматированном. Почитай правила форума, прежде чем постить свой понос в ветке.
...
Рейтинг: 0 / 0
24.12.2012, 12:22
    #38090452
skyANA
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
REDD13, Вам уже давали ответ, что не получается?
...
Рейтинг: 0 / 0
24.12.2012, 14:03
    #38090658
iConst
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
Вот так это делается на клиенте...
another shitcode
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Butts.aspx.cs" Inherits="WebApplication1.Butts" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script src="Scripts/WebForms/MSAjax/MicrosoftAjax.js"></script>
</head>
<body>
    <form id="form1" runat="server">

        <div>
            <asp:Literal ID="Literal1" runat="server"></asp:Literal>
            <table>
                <tbody id="buttsHolder"></tbody>
            </table>
        </div>
    </form>
    <script>
        var str = '';
        if (butts)
            for (var i = 0; i < butts.length; i++)
                str += String.format('<tr><td><span class="result"><span/></td><td><span><span/><input class="butt1" type="button" value="{0}"/></td><td><input class="butt2" type="button" value="{1}"/></td></tr>', butts[i].minPerc, butts[i].maxPerc);

        $('#buttsHolder').html(str);

        $('.butt1').click(function(e)
        {
            e.preventDefault();
            $(this).closest('tr').find('span.result').html((100 + parseInt(this.value)).toString());
        });

        $('.butt2').click(function(e)
        {
            e.preventDefault();
            alert(this.value);
        });

    </script>
</body>
</html>

Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
    public partial class Butts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // это типа из базы тянем кнопки :)
            var butts = new List<object>
            {
                new  {minPerc= 1, maxPerc= 99},
                new  {minPerc= 11, maxPerc= 98},
                new  {minPerc= 2, maxPerc= 85},
                new  {minPerc= 35, maxPerc= 77},
                new  {minPerc= 29, maxPerc= 62}
        
            };

            Literal1.Text = String.Format("<script>var butts={0};</script>", (new JavaScriptSerializer()).Serialize(butts));
        }
    }

...
Рейтинг: 0 / 0
24.12.2012, 14:14
    #38090683
skyANA
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
iConstВот так это делается на клиенте...
+
another shitcode
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Butts.aspx.cs" Inherits="WebApplication1.Butts" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script src="Scripts/WebForms/MSAjax/MicrosoftAjax.js"></script>
</head>
<body>
    <form id="form1" runat="server">

        <div>
            <asp:Literal ID="Literal1" runat="server"></asp:Literal>
            <table>
                <tbody id="buttsHolder"></tbody>
            </table>
        </div>
    </form>
    <script>
        var str = '';
        if (butts)
            for (var i = 0; i < butts.length; i++)
                str += String.format('<tr><td><span class="result"><span/></td><td><span><span/><input class="butt1" type="button" value="{0}"/></td><td><input class="butt2" type="button" value="{1}"/></td></tr>', butts[i].minPerc, butts[i].maxPerc);

        $('#buttsHolder').html(str);

        $('.butt1').click(function(e)
        {
            e.preventDefault();
            $(this).closest('tr').find('span.result').html((100 + parseInt(this.value)).toString());
        });

        $('.butt2').click(function(e)
        {
            e.preventDefault();
            alert(this.value);
        });

    </script>
</body>
</html>

Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
    public partial class Butts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // это типа из базы тянем кнопки :)
            var butts = new List<object>
            {
                new  {minPerc= 1, maxPerc= 99},
                new  {minPerc= 11, maxPerc= 98},
                new  {minPerc= 2, maxPerc= 85},
                new  {minPerc= 35, maxPerc= 77},
                new  {minPerc= 29, maxPerc= 62}
        
            };

            Literal1.Text = String.Format("<script>var butts={0};</script>", (new JavaScriptSerializer()).Serialize(butts));
        }
    }

Что это?
Советую сходить по ссылке выше и понять, откуда растут ноги проблемы автора.
...
Рейтинг: 0 / 0
08.01.2013, 01:20
    #38101897
mwebb
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Расчет при нажатии на кнопку. В расчет включить значение текста кнопки
Автор, ты не можешь sender привести к типу Button и прочитать его свойство Text, что ли? В этом проблема?
...
Рейтинг: 0 / 0
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Расчет при нажатии на кнопку. В расчет включить значение текста кнопки / 8 сообщений из 8, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]