Assuming you have a class you are using to fill the list with:
public class Data
{
public string Name { get; set; }
public int Age { get; set; }
}
You can automatically create the prerqeuisite rows by initializing a bound source with empty class instances like this:
List<data> InitialData = new List<data>()
{
new Data(),
new Data(),
new Data(),
new Data()
};
GridView1.DataSource = InitialData;
GridView1.DataBind();
</data></data>
or, using a count parameter in a method:
private void InitGrid(int NumberOfRows)
{
List<Data> InitialData = new List<Data>();
for (int i=0;i<NumberOfRows;i++)
{
InitialData.Add(new Data());
}
GridView1.DataSource = InitialData;
GridView1.DataBind();
}
This would be an example using page_load:
protected void Page_Load(object sender, EventArgs e)
{
InitGrid();
}
private void InitGrid()
{
int NumberOfRows = GetLocation();
List<Data> InitialData = new List<Data>();
for (int i = 0; i < NumberOfRows; i++)
{
InitialData.Add(new Data());
}
GridView1.DataSource = InitialData;
GridView1.DataBind();
}
private int GetLocation()
{
return 4;
}
Hope this gives you some ideas,
Juan de Villiers