简体   繁体   English

2 维随机值数组,其中包含 2 个用户从 asp.net 网络表单文本框输入的值

[英]2 dimensional random values array with 2 user entered values from asp.net web form textboxes

  1. prepare a form which accepts 2 numeric positive nos.准备一个接受 2 个数字正数的表格。 On clicking generate button, a 2 dimension array of 10 x 10 size will completely filled up with random numbers between those 2 user inputted numbers.单击生成按钮时,一个 10 x 10 大小的二维数组将完全填充这两个用户输入数字之间的随机数。

You will print the entire matrix on screen in 10 rows by 10 cols using a function.您将使用函数以 10 行 x 10 列的形式在屏幕上打印整个矩阵。

There will be one more button called transpose.还会有一个称为转置的按钮。 When user clicks on this button, entire matrix will be transposed.当用户点击这个按钮时,整个矩阵将被转置。 ie the all the data elements in rows will be interchanged with columns.即行中的所有数据元素将与列互换。 After transpose, it will get printed below again.转置后,它将再次打印在下面。 Both print should be visible to users.用户应该可以看到两个打印件。

    public void Button1_Click(object sender, EventArgs e)
    {
        int intLL = Convert.ToInt32(TextBox1.Text);
        int intUL = Convert.ToInt32(TextBox2.Text);
        int[,] arr = new int[size, size];
        for (int row =0; row < size;row++)
        {
            for(int col=0;col<size;col++)
            {
                arr[row, col] = r.Next(intLL,intUL);
                //Response.Output.Write(arr[row,col]+TextBox1.Text+TextBox2.Text+" ");
                Response.Output.Write(arr[row, col] + "  ");
            }
            Response.Write(" </br>");
        }
    }

    public void Button2_Click(object sender, EventArgs e)
    {

    }

i get the answer how to generate matrix with random values but on button_2 click event how i get transpose of matrix to display it on same screen我得到了如何用随机值生成矩阵的答案,但是在 button_2 单击事件上我如何得到矩阵的转置以在同一屏幕上显示它

Actually you are hardcoding the minimun and maximun values of your Random.Next call.实际上,您正在硬编码Random.Next调用的最小值和最大值。

Just check what the user entered in the textboxes and use that values instead.只需检查用户在文本框中输入的内容并改用该值即可。 After doing that you could do your traspoosing logic.这样做之后,你可以做你的 traspoosing 逻辑。

Something similar to:类似于:


int minValue = 0;
int maxValue = 0;

if (!Int.TryParse(tbMinimunValue, out minValue) || !Int.TryParse(tbMaximunValue, out maxValue))
{
    Response.Write("Please enter numbers");
    return;
}

// TODO: Add aditional checks like checking min < max, and min and max are positive values

Random r = new Random();
int size = 10;
int[,] arr = new int[size, size];
for (int i = 0; i < size;i++)
{
    for(int j=0;j<size;j++)
    {
        arr[i, j] = r.Next(minValue, maxValue);
        Response.Output.Write(arr[i,j]+" ");
    }
    Response.Write(" </br>");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将值放入文本框数组(使用C#的ASP.NET) - Taking values into an array of textboxes (ASP.NET using C#) 无法获取在 ASP.NET MVC 表单中输入的值 - Can't get values ​entered in ASP.NET MVC Form 如何在 ASP.NET 中将值从 Web 表单传递给另一个? - How pass a values from a web form to another in ASP.NET? 如何使用c#将asp.net中数据库中的数据赋值到二维数组? - How to assing values to 2 dimensional array with data from database in asp.net using c#? 如何在JavaScript中使用具有相同ID的两个文本框获取asp.net用户控件的值 - How to get the values of an asp.net user control with two textboxes with same id in javascript 如何在ASP.NET Web表单中使用Ajax更新ListView中的值 - How to update values in a ListView with ajax in asp.net web form Asp.net MVC中两个文本框的求和值 - Summing values of two textboxes in Asp.net MVC 尝试在ASP.NET中的ListView中的代码后面的文本框中分配值 - Attempting to assign values to TextBoxes in code behind in ListView in ASP.NET 在 ASP.Net 中使用 JavaScript 将“启用的文本框”中的值相乘 - Multiply the values in the “Enabled TextBoxes” Using JavaScript in ASP.Net 如何在Asp.net MVC中乘以两个文本框的值 - How to multiply values of two textboxes in Asp.net MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM