datagrid

删除 

datagrid

<div onclick='return confirm("你确认删除吗?");'>删除</div>

private   void  Dg_DeleteCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            
int  id  =  Convert.ToInt32(e.Item.Cells[ 0 ].Text); 
            QsqPageContent pc
= new  QsqPageContent();    
            pc.Id
= id;        
            DataAccessReturn pcD 
=  pc.Delete();
            Bind();            
        }

 

编辑

如果不允许编辑则勾选“只读”,如不想显示则勾选“可见”,计算item[]时要计算在内,仍然保留了其列号。

private   void  Dg_EditCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Dg.EditItemIndex 
=  e.Item.ItemIndex;
            Bind();
        }
        
private   void  Dg_CancelCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Dg.EditItemIndex 
=   - 1 ;
            Bind();
        }
        
private   void  Dg_UpdateCommand( object  source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            
int  ID  =   int .Parse(e.Item.Cells[ 0 ].Text);
            
string  showName   =  ((TextBox)e.Item.Cells[ 3 ].Controls[ 0 ]).Text;
            
int  orderBy  =  Components.Tools.TypeParse.StrToInt(((TextBox)e.Item.Cells[ 4 ].Controls[ 0 ]).Text, 0 );    
            QsqPageContent pc 
=   new  QsqPageContent();
            pc.Id 
=  ID;
            pc.ShowName
= showName;
            pc.OrderBy
= orderBy;
            pc.Update();
            Dg.EditItemIndex 
=   - 1 ;
            Bind();
        }

改变datagrid列宽度

模板列:编辑时的宽度调整方式(Width="100px")绑定显示宽度同位置调整一样在第一行(

HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"

Code

 

绑定列:绑定显示宽度所有列都一样在html里调整,但编辑状态下的列宽度则在Dg_ItemDataBound

Code
编辑状态下
Code

由于编辑状态下text都变成了textbox需要写成上面那样,如改为只读则 string state = e.Item.Cells[7].Text; 

 

自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺让人头疼,

1.(IE浏览器)连续的英文字符和阿拉伯数字,使用word-wrap : break-word ;或者word-break:break-all;实现强制断行

Dg_ItemDataBound里

Code

你可能感兴趣的:(datagrid)