I want to bind a arraylist to grid in asp.net c#? [duplicate]
Possible Duplicate:
I want to bind a arraylist to grid in asp.net c#?
nsecashservice serviceofgainers = new nsecashservice();
int idd = serviceofgainers.maxID();
System.Collections.ArrayList copygrid = new System.Collections.ArrayList();
System.Collections.ArrayList开发者_JS百科 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;
}
this code i have done in window application i want to change it to asp.net c#. in this I am getting an array list of 1500 rows of data containing 4 columns of data. Please help me to to change this code.
When you change it to asp.net I think you can change the data into datatable with those columns
Supposed you have the GridView gvResults in you aspx page in your code behind page, after you get data into DataTable (dt for example)
gvResults.DataSource = dt;
gvResults.DataBind();
in your aspx page you can use
<asp:BoundField HeaderText="Your Name" DataField="column_name_in_table" ReadOnly="true" />
or
<asp:TemplateField HeaderText="Your Name">
<ItemTemplate>
<%# Eval("column_name_in_table")%>
</ItemTemplate>
</asp:TemplateField>
精彩评论