Reputation: 872
Hi i am looking for having 10 records in the grid-view by default
so if the grid-view has 3 rows then there are 7 empty rows to add,
if grid-view has 4 rows then there are 6 empty rows, etc..
also if grid-view has 10 rows there's no empty rows to add
QueryClass q = new QueryClass();
grid.DataSource = q.getdata();
grid.DataBind();
Method
public DataTable getdata()
{
string query = string.Format("SELECT TOP(10) * FROM Store");
return Search(query);
}
Upvotes: 3
Views: 407
Reputation: 30022
You can Add the missing items to your datasource:
QueryClass q = new QueryClass();
var dSource = q.getdata();
foreach (var missing in Enumerable.Range(1, 10 - dSource.Rows.Count))
{
dSource.NewRow();
}
grid.DataSource = dSource;
grid.DataBind();
Upvotes: 1
Reputation: 5596
You could create an extension method for this:
public static class HelperMethod
{
public static List<QueryClassObj> Extend(this List<QueryClassObj> items)
{
while (items.Count < 10)
{
items.Add(new QueryClassObj());
}
return items;
}
}
When you get the data and bind to your grid simply:
QueryClass q = new QueryClass();
grid.DataSource = q.getdata().Extend();
grid.DataBind();
Based on your edit you can try this
public DataTable getdata()
{
string query = string.Format("SELECT TOP(10) * FROM Store");
DataTable results= Search(query);
while(results.Rows.Count<10)
{
results.Rows.Add(results.NewRow());
}
}
Sorry I have not been able to test my last edit as I'm away from PC
Upvotes: 3