使用不带DataBinding的Asp.net GridView [英] Working with Asp.net GridView without DataBinding

查看:111
本文介绍了使用不带DataBinding的Asp.net GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用数据填充asp.net GridView并在没有dataBinding的情况下对这些数据进行操作,因为使用Winforms DataGridView

解决方案

将数据源添加到数据表中,您可以使用任何您喜欢的代码在代码中构建数据源。


table.Columns.Add(Column1);
table.Columns.Add(Column2);

var row = table.NewRow();
row [Column1] =test;
row [Column2] =test2;

table.Rows.Add(row);

GridView.DataSource = table;
GridView.DataBind();

您也可以使用列表设置gridview的数据源:

  var yourList = new List< YourRowStuff>(); 

从数据库查询中获取列表或者在代码中手动构建列表....

  GridView.DataSource = yourList; 
GridView.DataBind();


Is it possible to populate asp.net GridView with data and operate on those data without dataBinding, as it is possible with Winforms DataGridView?

解决方案

You can set the data source to a datatable that you can build up in code with whatever you like.

 var table = new DataTable();
 table.Columns.Add("Column1");
 table.Columns.Add("Column2");

var row = table.NewRow();
row["Column1"] = "test";
row["Column2"] = "test2";

table.Rows.Add(row);

GridView.DataSource = table;
GridView.DataBind();

You can also set a gridview's data source with a list:

var yourList = new List<YourRowStuff>();

get the list from a database query or build it up manually in code....

GridView.DataSource = yourList;
GridView.DataBind();

这篇关于使用不带DataBinding的Asp.net GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆