怎么样把数据库中的字段绑定gridview里

来源:百度知道 编辑:UC知道 时间:2024/07/08 02:21:53
<asp:BoundField DataField="RoleId" HeaderText="角色ID" SortExpression="RoleId" />
<asp:BoundField DataField="RoleName" HeaderText="角色名称" SortExpression="RoleName" />
<asp:BoundField DataField="RoleDesc" HeaderText="角色描述" SortExpression="RoleDesc" />
<asp:BoundField DataField="DisCount" HeaderText="备注" SortExpression="DisCount" />
这是页面源时在的
下面是我后台是方法
//public static IList<RoleInfo> GetAllRoleInfos()
//{
//// string sql = "select * from RoleInfo";
//// return GetRoleInfosBySql(sql);
//}
private static IList<RoleInfo> GetRoleInfosBySql(string safeSql)
{
List<RoleInfo> list = new List<RoleInfo>();
using (DataTable table = DBHelper.GetDa

cmd.CommandType = CommandType.StoredProcedure;
所以会把语句认成过程

Dataset ds=new Dataset();
gridview.datasource=ds.table[0];
gridview.databind();
将查询到的数据放在DataSet里面,然后将Gridview绑定在Dataset上就行了