Grid控件的操作

 grid_ItemDataBound(object sender, DataGridItemEventArgs e)中:

protected   void  grid_ItemDataBound( object  sender, DataGridItemEventArgs e)
    
{
       
//当为1时,显示已审,当为0时,显示未审
        foreach (DataGridItem a in grid.Items)
        
{
            
if (a.Cells[11].Text.ToString().Trim() == "1")
           
{

               a.Cells[
11].Text = "已审";
                  a.Cells[15].ForeColor = System.Drawing.Color.Red;//把未审的颜色变成蓝色
                    a.Cells[16].Enabled = false;//修改和删除不可用
                    a.Cells[17].Enabled = false;

           }


           
if (a.Cells[11].Text.ToString().Trim() == "" || a.Cells[11].Text.ToString().Trim() == "0" || a.Cells[11].Text.ToString().Trim() == "NULL")
           
{
              a.Cells[
15].Text = "未审";
                 a.Cells[15].ForeColor = System.Drawing.Color.Blue;//把未审的颜色变成蓝色
          }


       }

        当显示审核时,修改和删除不可用
!!
        
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        
{
            
if (e.Item.Cells[15].Text.Trim() == "已审")
            
{
                
foreach (HyperLink lb in e.Item.Cells[17].Controls)
                
{
                    
if (lb != null)
                    
{
                        lb.Enabled 
= false;
                        lb.Attributes[
"onClick"= "";
                    }

                }

                
foreach (HyperLink lb in e.Item.Cells[18].Controls)
                
{
                    
if (lb != null)
                    
{
                        lb.Enabled 
= false;
                        lb.Attributes[
"onClick"= "";
                    }

                }

            }

        }

        
//以下为样例,请参照使用
        foreach (System.Web.UI.WebControls.HyperLink link in e.Item.Cells[18].Controls)
        
{
            link.Attributes.Add(
"onClick""if (!window.confirm('您真的要删除这条记录吗?')){return false;}");
        }

        
if (e.Item.ItemIndex >= 0)//设置表格中鼠标经过的色彩
        {
            
string title = "#FFFF00";
            
string bgcolor = "#FFFFFF";
            e.Item.Attributes.Add(
"onMouseOver""this.style.backgroundColor='" + title + "'; this.style.cursor='hand';");
            e.Item.Attributes.Add(
"onMouseOut""this.style.backgroundColor='" + bgcolor + "';");
        }

    }
 

grid_ItemCommand(object source, DataGridCommandEventArgs e)中:

  protected   void  grid_ItemCommand( object  source, DataGridCommandEventArgs e)
    
{
           
if (e.CommandName == "aa")
           
{
                    
if (e.Item.Cells[7].Text.Trim() != "" || e.Item.Cells[8].Text.Trim() != "")
                   
{
                           Response.Redirect(
"add/AddTheory.aspx");
                           Session[
"strWhere"= ID;
                   }

                   
else
                  
{
                           Response.Redirect(
"add/AddGrm.aspx");
                  }

           }

    }

 

 

//审核选定的记录
    protected void Confirm_Click(object sender, EventArgs e)
    {
        string dgIDs = "";
        bool BxsChkd = false;

        foreach (DataGridItem item in grid.Items)
        {
            CheckBox ChkBxItem = (CheckBox)item.FindControl("UpdateThis");
            if (ChkBxItem.Checked)
            {
                BxsChkd = true;
                //注意必须正确指出ID列单元,是隐藏的,单引号和逗号必须要
                dgIDs += "'" + item.Cells[0].Text + "',";
            }
        }
        if (BxsChkd)
        {
            dgIDs = dgIDs.Substring(0, dgIDs.LastIndexOf(","));
            //产生业务对象进行更新操作,审核和去审核的公用类
            PFCMIS.BLL.CommonCheck bllcc = new PFCMIS.BLL.CommonCheck();
            bllcc.CheckMark("CheckMark", "ID", "StuPracGrad", dgIDs);
            Response.Redirect("Index.aspx");
        }
    }
 

    //去掉审核选定的记录
    protected void UnConfirm_Click(object sender, EventArgs e)
    {
        string dgIDs = "";
        bool BxsChkd = false;
        foreach (DataGridItem item in grid.Items)
        {
            CheckBox deleteChkBxItem = (CheckBox)item.FindControl("UpdateThis");
            if (deleteChkBxItem.Checked)
            {
                BxsChkd = true;
                //注意必须正确指出ID列单元,是隐藏的,单引号和逗号必须要
                dgIDs += "'" + item.Cells[0].Text + "',";
            }
        }
        if (BxsChkd)
        {
            dgIDs = dgIDs.Substring(0, dgIDs.LastIndexOf(","));
            //产生业务对象进行更新操作,审核和去审核的公用类
            PFCMIS.BLL.CommonCheck bllcc = new PFCMIS.BLL.CommonCheck();
            bllcc.UnCheckMark("CheckMark", "ID", "StuPracGrad", dgIDs);
            Response.Redirect("Index.aspx");
        }
    }

控件使用 1、鼠标经过行的时候改变该行的样式,鼠标离开行的时候恢复该行的样式 使用方法(设置属性): MouseOverCssClass - 鼠标经过行时行的 CSS 类名 2、对多个字段进行复合排序;升序、降序的排序状态提示 使用方法(设置SmartSorting复合属性): AllowSortTip - 是否启用排序提示 AllowMultiSorting - 是否启用复合排序 SortAscImageUrl - 升序提示图片的URL(不设置则使用默认图片) SortDescImageUrl - 降序提示图片的URL(不设置则使用默认图片) SortAscText - 升序提示文本 SortDescText - 降序提示文本 3、根据按钮的CommandName设置其客户端属性 使用方法(设置ClientButtons集合属性): BoundCommandName - 需要绑定的CommandName AttributeKey - 属性的名称 AttributeValue - 属性的值(两个占位符:{0} - CommandArgument;{1} - Text) Position - 属性的值的位置 4、联动复选框(复选框的全选和取消全选)。选中指定的父复选框,则设置指定的所有子复选框为选中状态;取消选中指定的父复选框,则设置指定的所有子复选框为取消选中状态。如果指定的所有子复选框为均选中状态,则设置指定的父复选框为选中状态;如果指定的所有子复选框至少有一个为取消选中状态,则设置指定的父复选框为取消选中状态 使用方法(设置CascadeCheckboxes集合属性): ParentCheckboxID - 模板列中 父复选框ID ChildCheckboxID - 模板列中 子复选框ID CashBox.Helper.WebGrid中的静态方法 List GetCheckedDataKey(GridView gv, int columnIndex) List GetCheckedDataKey(GridView gv, string checkboxId) 5、固定指定行、指定列,根据RowType固定行,根据RowState固定行 使用方法(设置FixRowColumn复合属性): FixRowType - 需要固定的行的RowType(用逗号“,”分隔) FixRowState - 需要固定的行的RowState(用逗号“,”分隔) FixRows - 需要固定的行的索引(用逗号“,”分隔) FixColumns - 需要固定的列的索引(用逗号“,”分隔) TableWidth - 表格的宽度 TableHeight - 表格的高度 6、响应行的单击事件和双击事件,并在服务端处理 使用方法(设置属性): BoundRowClickCommandName - 行的单击事件需要绑定的CommandName BoundRowDoubleClickCommandName - 行的双击事件需要绑定的CommandName 7、行的指定复选框选中的时候改变该行的样式,行的指定复选框取消选中的时候恢复该行的样式 使用方法(设置CheckedRowCssClass复合属性): CheckBoxID - 模板列中 数据行的复选框ID CssClass - 选中的行的 CSS 类名 8、导出数据源的数据为Excel、Word或Text(应保证数据源的类型为DataTable或DataSet) 使用方法: 为WebGrid添加的方法 Export(string fileName) Export(string fileName, ExportFormat exportFormat) Export(string fileName, ExportFormat exportFormat, Encoding encoding) Export(string fileName, int[] columnIndexList, ExportFormat exportFormat, Encoding encoding) Export(string fileName, int[] columnIndexList, string[] headers, ExportFormat exportFormat, Encoding encoding) Export(string fileName, string[] columnNameList, ExportFormat exportFormat, Encoding encoding) Export(string fileName, strin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值