请问答案,当我在多组框中动态生成radiobutton时,它在一个组框中工​​作 [英] Pls, I want an answer , , when I generate radiobutton dynamically in multi groupbox , it works as they in one groupbox

查看:82
本文介绍了请问答案,当我在多组框中动态生成radiobutton时,它在一个组框中工​​作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望每个groupBox单独工作

这里是代码

------------- -------------------------------------------------- ------

i want each groupBox work alone
and here is the code
---------------------------------------------------------------------

            Random rnd = new Random();
            int mo = rnd.Next(1, 5);  // 1 <= month < 13
            int check = 0;
            Random rand = new Random();
            int[] lotto = new int[5];
            for (int i = 0; i < lotto.Length; )
            {
                check = rand.Next(1, 10);

                if (!lotto.Contains(check))
                {
                    lotto[i] = check;
                    i++;
                }

            }
            VScrollBar scb = new VScrollBar();
            scb.Height = 200;
            scb.Width = 10;
            SqlConnection con = new SqlConnection("Data Source=ahmed-hp\\exp;Initial Catalog=Elearning;Integrated Security=True");
        SqlCommand cmd;
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select Qu_sec,Qu_name from Qustions where Qu_sec in(" + lotto[0] + "," + lotto[1] + "," + lotto[2] + "," + lotto[3] + "," + lotto[4] + ")", con);
DataTable dt = new DataTable();
da.Fill(dt);
for (int o = 0; o < 5; o++)
{
    Label lb = new Label();
    lb.Name = lb1 + o.ToString();
    sd = dt.Rows[o][1].ToString();
    lb.AutoSize = true;
    lb.Text = (o + 1).ToString() + " - " + sd; 
    lb.Location = new Point(100 , (100 + o * 130));
    lb.Font = new Font(lb.Font, FontStyle.Bold);
    this.Controls.Add(lb);

    SqlDataAdapter da1 = new SqlDataAdapter("select An_name,An_true from Answers where An_sec='" + dt.Rows[o][0].ToString() + "'", con);
    DataTable dt1 = new DataTable();
    da1.Fill(dt1);
    GroupBox gb = new GroupBox();
    gb.Name = "gb" + o.ToString();
    gb.Location = new Point(60, 110+o*130);
    gb.Size = new Size(50, 105);
    gb.Text = o.ToString();
    for (int k = 0; k < 4; k++)
    {
        if ((bool)(dt1.Rows[k][1]) == true)
        {
            vc[o] = k + 1;
        }
        
        RadioButton rb = new RadioButton();
        rb.Name = "rb" +o.ToString()+ k.ToString();
        Label lbl = new Label();
        lbl.Name = lb1 + k.ToString();
         lbl.AutoSize = true;
        lbl.Text = "      - " + dt1.Rows[k][0].ToString();
        rb.Location = new Point(80, (100 + (o * 130) + (k + 1) * 22));
        lbl.Location = new Point(100, (100 + (o *130) +(k+1)* 22));
        this.Controls.Add(lbl);
        gb.Controls.Add(rb);
        this.Controls.Add(rb);
       
     }

     this.Controls.Add(gb);
    this.Update();



----------- ----------------------------------------------



我尝试了什么:



i希望每个groupbox单独使用他们的RadioButton

最好的问候所有人


---------------------------------------------------------

What I have tried:

i want each groupbox work alone with thier RadioButton
Best Regards to all of you

推荐答案

不是你注意到的问题的解决方案,但是你需要在整个应用程序中解决一个严重的问题在你考虑前进之前。



永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。



连接字符串时会导致问题,因为SQL会收到如下命令:

Not a solution to the problem you have noticed, but a serious problem you need to address throughout your application before you even think about moving forward.

Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'

就SQL而言,用户添加的引号会终止字符串,并且您会遇到问题。但情况可能更糟。如果我来并改为输入:x'; DROP TABLE MyTable; - 然后SQL收到一个非常不同的命令:

The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:

SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'

哪个SQL看作三个单独的命令:

Which SQL sees as three separate commands:

SELECT * FROM MyTable WHERE StreetAddress = 'x';

完全有效的SELECT

A perfectly valid SELECT

DROP TABLE MyTable;

完全有效的删除表格通讯和

A perfectly valid "delete the table" command

--'

其他一切都是评论。

所以它确实:选择任何匹配的行,从数据库中删除表,并忽略其他任何内容。



所以总是使用参数化查询!或者准备好经常从备份中恢复数据库。你定期做备份,不是吗?

And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?


我认为你应该使用:
gb.Controls.Add(rb)

并删除:

this.Controls.Add(rb);


这篇关于请问答案,当我在多组框中动态生成radiobutton时,它在一个组框中工​​作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆