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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Suthish NairRank #92 · 22.8K reputationPosted Mar 9, 2011, 1:02 AM EST
using System.Data;
GridView dgv = new GridView();
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 8, 2011, 9:28 PM EST
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.
hamida khanam91 reputationPosted Mar 9, 2011, 12:32 AM EST
But I had to use it for web application not windows.Can you tell me please how to do it in web applications
Suthish NairRank #92 · 22.8K reputationPosted Mar 10, 2011, 8:18 AM EST
hamida khanam91 reputationPosted Mar 10, 2011, 8:05 PM EST
Thanks Satish for helping and many many thanks to Amit for giving exact core solution to the problem.