nsecashservice serviceofgainers = new nsecashservice();
int idd = serviceofgainers.maxID();
System.Collections.ArrayList copygrid = new System.Collections.ArrayList();
System.Collections.ArrayList grid = new System.Collections.ArrayList();
grid = serviceofgainers.getdata(idd);
copygrid = grid;
System.Collections.ArrayList losers = new System.Collections.ArrayList();
this.dataGridView1.DefaultCellStyle.BackColor = Color.Bisque;
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Salmon;
dataGridView1.Columns.Add("Sl.No", "Sl.No");
// Console.WriteLine("column width: " + dataGridView1.Columns[0].Width);
dataGridView1.Columns.Add("scripName", "Company");
dataGridView1.Columns.Add("prevClose", "previousClose");
dataGridView1.Columns.Add("closeValue", "closeValue");
dataGridView1.Columns.Add("percentDiff", "percentDiff");
//int row = grid.Count - 1;
for (int r = 0; r <= 14; r++)
{
scripinfo inf = grid[r] as scripinfo;
//Console.WriteLine("Row count" + dataGridView1.Rows.Count);
dataGridView1.Rows.Add();
dataGridView1.Rows[r].Cells[0].Value = r + 1;
dataGridView1.Rows[r].Cells[1].Value = inf.scripName;
dataGridView1.Rows[r].Cells[1].Style.ForeColor = System.Drawing.Color.Blue;
dataGridView1.Rows[r].Cells[2].Value = Math.Round(inf.prevClose, 2);
dataGridView1.Rows[r].Cells[3].Value = Math.Round(inf.closeValue, 2);
dataGridView1.Rows[r].Cells[4].Value = Math.Round(inf.percentDiff, 2);
dataGridView1.Rows[r].Cells[4].Style.ForeColor = System.Drawing.Color.Green;
}
这个代码我已经在窗口应用程序中完成了我想把它改成asp.net c#。在这里我得到一个包含4列数据的1500行数据的数组列表。请帮我改变这段代码。
答案 0 :(得分:0)
当您将其更改为asp.net时,我认为您可以使用这些列将数据更改为数据表
假设您在aspx页面中有GridView gvResults 在您的代码隐藏页面后,将数据导入DataTable(例如dt)
gvResults.DataSource = dt;
gvResults.DataBind();
在您的aspx页面中,您可以使用
<asp:BoundField HeaderText="Your Name" DataField="column_name_in_table" ReadOnly="true" />
或
<asp:TemplateField HeaderText="Your Name">
<ItemTemplate>
<%# Eval("column_name_in_table")%>
</ItemTemplate>
</asp:TemplateField>