Add Column in GridView on Run Time using LINQ in ASP.Net

Last Reply one month ago By pandeyism

Posted one month ago

Add column run time.

so on run time i want to see the condition of row return and add another column RANK which i want to add in query result and bind to gridview so when page load gridview shows following column countryid (get from database) countryname (get from database) rank  (add on run time conditionally)

countryid  countrname

1            India

2            USA

3            China

var q = (from c in db.Countries
            select c).ToList();
string rank;
foreach (var item in q)
{
    if (item.Countryid == 1)
    {

        rank = "Top";
    }
    if (item.Countryid == 1)
    {

        rank = "second";
    }
}
GridView1.DataSource = q.ToList();
GridView1.DataBind();

 

This question does not have replies that have been liked.