最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net中DataGrid双行跨列跨行复杂表头设计心得!
时间:2022-07-02 11:59:51 编辑:袖梨 来源:一聚教程网
一、DataGrid的属性设置
1. AllowPaging: true
2. PageStyle->Position: TopAndBottom
3. 可选:PageStyle->HorizonAlign: Center(使文本居中显示)
4. 可选:ItemStyle->HorizonAlign: Center(使文本居中显示)
二、代码部分
1.首先,使DataGrid绑定数据库中某个表,例如:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
SqlConnection myConn=new SqlConnection("server=localhost;uid=sa;pwd=sa;database=db_test");
SqlDataAdapter da=new SqlDataAdapter("Select * from 个人",myConn);
DataSet ds=new DataSet();
da.Fill(ds,"gr");
dgGeRen.DataSource=ds.Tables["gr"].DefaultView;
dgGeRen.DataBind();
}
2.为DataGrid添加ItemCreated事件的处理函数、
3.为了判断DataGrid中的两个(上下)Pager的位置,我们可以使用一个全局变量来判断。
定义一个全局变量 private int m_CreatePageTimes = 0;
4.为DataGrid的ItemCreated事件的处理函数添加内容,如下:
private void dgGeRen_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
1. AllowPaging: true
2. PageStyle->Position: TopAndBottom
3. 可选:PageStyle->HorizonAlign: Center(使文本居中显示)
4. 可选:ItemStyle->HorizonAlign: Center(使文本居中显示)
二、代码部分
1.首先,使DataGrid绑定数据库中某个表,例如:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
SqlConnection myConn=new SqlConnection("server=localhost;uid=sa;pwd=sa;database=db_test");
SqlDataAdapter da=new SqlDataAdapter("Select * from 个人",myConn);
DataSet ds=new DataSet();
da.Fill(ds,"gr");
dgGeRen.DataSource=ds.Tables["gr"].DefaultView;
dgGeRen.DataBind();
}
2.为DataGrid添加ItemCreated事件的处理函数、
3.为了判断DataGrid中的两个(上下)Pager的位置,我们可以使用一个全局变量来判断。
定义一个全局变量 private int m_CreatePageTimes = 0;
4.为DataGrid的ItemCreated事件的处理函数添加内容,如下:
private void dgGeRen_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
相关文章
- 《异界事务所》光谱项链哪几种 06-30
- 《雾境序列》波比角色大全全解析 06-30
- 《星球重启》SSR宠物盲盒免费怎么获得 06-30
- 操作教程:常见的NFT被盗手段?为什么NFT玩家成为黑客目标? 06-30
- 拳皇97风云再起出招表-拳皇97风云再起技能招式表一览 06-30
- 鸣潮坎特蕾拉培养攻略-鸣潮坎特蕾拉培养材料一览 06-30