-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-grid-view.aspx.cs
68 lines (59 loc) · 1.71 KB
/
load-grid-view.aspx.cs
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
public Random random = new Random();
protected void Page_Load(object sender, EventArgs e)
{
// # columns, # rows, useNumeric (T/F), rowLength, minNumber, maxNumber
LoadGridView(4, 12, true, 14, 500, 1500);
}
public void LoadGridView(int columnCount, int rowCount, bool useNumeric, int rowLength, int minNumber, int maxNumber)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn(" ", typeof(string)));
for (int c = 0; c < columnCount; c++)
{
string columnName = RandomString(rowLength, false);
if(useNumeric==true)
{
dt.Columns.Add(new DataColumn(columnName, typeof(Int32)));
}
else
{
dt.Columns.Add(new DataColumn(columnName, typeof(string)));
}
}
for (int j = 1; j <= rowCount; j++)
{
DataRow dr = dt.NewRow();
dr[0] = RandomString(4, false);
for (int k = 1; k <= columnCount; k++)
{
if (useNumeric == true)
{
dr[k] = RandomNumber(minNumber, maxNumber);
}
else
{
dr[k] = RandomString(rowLength, true);
}
}
dt.Rows.Add(dr);
}
gvExample.DataSource = dt;
gvExample.DataBind();
}
private int RandomNumber(int min, int max)
{
return random.Next(min, max);
}
private string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
if (lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}