开发者

columns not shown when binding to gridview using linq to sql with an empty datasource

Is there a way to display the columns of the data you are selecting from when binding to a datagrid with an empty datasource? Whenever I bind with an empty datasource, the grid won't even show.

var results = from t in db.vwTaskInfos where t.PriorityId ==  Convert.ToInt32(drdPriority.SelectedValue) select t;

    开发者_如何学运维     gvTasks.DataSource = results;
         gvTasks.AutoGenerateColumns = true;
         gvTasks.DataBind();


var results = from t in db.vwTaskInfos where t.PriorityId ==  Convert.ToInt32(drdPriority.SelectedValue) select t;

         gvTasks.DataSource = results;
         gvTasks.AutoGenerateColumns = true;
         gvTasks.DataBind();

Change to:

var results = from t in db.vwTaskInfos where t.PriorityId ==  Convert.ToInt32(drdPriority.SelectedValue) select t;

         gvTasks.DataSource = results.ToList();
         gvTasks.AutoGenerateColumns = true;
         gvTasks.DataBind();

Notice I changed "gvTasks.DataSource = results;" to "gvTasks.DataSource = results.ToList();"

EDIT:

I see, your problem is not actually a linq to sql issue. It's a grid view issue. That being said, here is the solution you're looking for:

GridView - Show headers on empty data source

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜