Hello All
How I fill grid 10x 10 with random numbers using random function
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Mar 9, 2011, 6:02 AM
using System.Data;
GridView dgv = new GridView();
hamida khanamPosted Mar 11, 2011, 1:05 AM
Thanks Satish for helping and many many thanks to Amit for giving exact core solution to the problem.
Suthish NairPosted Mar 10, 2011, 1:18 PM
hamida khanamPosted Mar 9, 2011, 5:32 AM
But I had to use it for web application not windows.Can you tell me please how to do it in web applications
Amit ChoudharyPosted Mar 9, 2011, 2:28 AM
Create a datasource for e.g. datatable fill it with random no's having 10 rows and 10 columns and bind it with your GridView.
Below is the example for widows application:
private void Form1_Load(object sender, EventArgs e)
{
DataGridView dgv = new DataGridView();
DataTable dt = new DataTable();
DataRow dr;
Random rnd=new Random();
for (int j = 0; j < 10; j++)
{
dt.Columns.Add(new DataColumn());
}
for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
for (int col = 0; col < 10; col++)
{
dr[col] = (int)rnd.Next(1,10000);
}
dt.Rows.Add(dr);
}
dgv.DataSource = dt;
this.Controls.Add(dgv);
}
The code in blue is the code to create the DataTable.
Please mark "Do you like this answer" if it helps you.
Thansk.