UltraWebGrid

       最近做项目用到UltraWebGrid,发现功能蛮强大的,把搜集到得和用到的一些功能做下总结了,放在这里吧。

 

     一、 一些基本应用

  

   1. UltraWebGrid添加模板列:
      先选择UltraWebGrid --属性--columns--勾选Templated column 即可
     
       <igtbl:TemplatedColumn AllowResize="Free" BaseColumnName="BT" ChangeLinksColor="True"
                            HeaderText="标题" Key="BT" Type="HyperLink">
                            <CellTemplate>
                                <asp:LinkButton ID="LinkButton1" CssClass="WordBreak" CommandArgument='<%# DataBinder.(Container.DataItem,"AQJYGXID") %>' Text='<%# DataBinder.(Container.DataItem,"BT") %>' ToolTip='<%# DataBinder.(Container.DataItem,"BT") %>' CommandName="showdetail" runat="server" Font-Underline="false"></asp:LinkButton>
                            </CellTemplate>
                            <Header Caption="标题">
                                <RowLayoutColumnInfo OriginX="2" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="2" />
                            </Footer>
                        </igtbl:TemplatedColumn>


2. UltraWebGrid日期列:
      设置日期列的 Format属性:yyyy-MM-dd(Date)
      DataType属性为System.DateTime


3.取某行的某列(列名:BIDPRICE)的值: 
UltraWebGrid1.Rows[i].Cells.FromKey("BIDPRICE").Value或者UltraWebGrid1.Rows[i].Cells[j].Value 
取某列:UltraWebGrid1.Columns.FromKey("BIDPRICE").Value


4.标题行居中显示:
      <HeaderStyleDefault BackColor="LightGray" BorderStyle="Solid" HorizontalAlign="Center">
                 </HeaderStyleDefault>
  
对应项居中    <CellStyle HorizontalAlign="Center"></CellStyle>

 

5.UltraWebGrid的固定列功能
    具体步骤:
        (1) 在UltraWebGrid下的DisplayLayout中把TableLayout属性设为:Fixed ; UseFixedHeaders设为:True //这是指定Grid允许固定列
StationaryMargins="Header" //这使Header始终在最上面显示
(2) 设定列固定: Header下面的Fixed设置为true。这样就可以实现ID固定了,但效果图中还有一个功能就是,点击后面的任何一个列后的“图钉”图标,就可以任意进行多列固定了。如下图为我点击了“ContactName”的效果:这种功能的实现,只要修改一个属性:FixedHeaderIndicatorDefault="Button"就可以了。

 

6。UltraWebGrid 最下面线显示问题:
       选择UltraWebGrid点击》选择Bands And Columns的DefaultrowHeight设置高度 即可。


7.   选择一行以后获得选定行指定列的值
if (e.InnerCommandEventArgs.CommandName == "showdetail")
        {
            int id = Convert.ToInt32(e.InnerCommandEventArgs.CommandArgument);
          
            for (int i = 0; i < UltraWebGrid1.DisplayLayout.SelectedRows.Count; i++)
            {
                if (UltraWebGrid1.DisplayLayout.SelectedRows[i].Cells[6].Text == "未审批")//选取一行以后获得选定行指定列的值
               {
                    string url2 = "../zhishishenbaobiao/zssbview.aspx?id=" + id + " ";
                    Page.RegisterStartupScript("showinfo", "<script>window.open('" + url2 + "','未审批知识信息查看','width=850,height=600,toolbar=no,scrollbars=yes,status=yes,resizable=yes');</script>");

                }
                else
                {
                    string url2 = "../zhishishenbaobiao/showview.aspx?id=" + id + " ";
                    Page.RegisterStartupScript("showinfo", "<script>window.open('" + url2 + "','已审批知识信息查看','width=850,height=600,toolbar=no,scrollbars=yes,status=yes,resizable=yes');</script>");

                }
            }
          
        }

 

7. UltraWebGrid 单击单元格选中行
        (1) 选择UltraWebGrid-displayout CellClickActionDefault=RowSelected
        (2)   选择UltraWebGrid-智能选择卡--Bands And Columns--Band[“”]--SelectRowStyle的BackColor属性
 

8. 设置UltraWebGrid的第0列为模板列,加入CheckBox控件,判断其状态是否被选中,代码如下:   

       //可以写在任何地方,属于通用代码
Infragistics.WebUI.UltraWebGrid.TemplatedColumn    tcol   =   (TemplatedColumn)UltraWebGrid1.Bands[0].Columns[0];//模板列
foreach(CellItem    item   in    tcol.CellItems)
   {            
           System.Web.UI.WebControls.CheckBox    chkIsHaveRight   =    (System.Web.UI.WebControls.CheckBox)item.FindControl("chbShenhe");
          if(chkIsHaveRight.Checked == true)
           {
                  //进行相关的操作
            }
   }


9.禁止操作列
(1) 禁止操作一列数据
   Infragistics.WebUI.UltraWebGrid.TemplatedColumn tcol = (TemplatedColumn)UltraWebGrid1.Bands[0].Columns[9];//模板列
                    foreach (CellItem item in tcol.CellItems)
                    {
                        System.Web.UI.WebControls.ImageButton chkIsHaveRight = (System.Web.UI.WebControls.ImageButton)item.FindControl("ImageButton3");
                        chkIsHaveRight.Enabled = false;
                    }
(2) 禁止操作某列中已审批列
Infragistics.WebUI.UltraWebGrid.TemplatedColumn tcol = (TemplatedColumn)UltraWebGrid1.Bands[0].Columns[9];//模板列
     foreach (CellItem item in tcol.CellItems)
                        {
                            System.Web.UI.WebControls.ImageButton chkIsHaveRight = (System.Web.UI.WebControls.ImageButton)item.FindControl("ImageButton3");
                            if (item.Cell.Row.Cells[6].Text == "已审批")
                            {
                                chkIsHaveRight.Enabled = false;//已审批按钮禁止选择
                            }
                            else
                            {
                                chkIsHaveRight.Enabled = true;
                            }

                        }


10. webgrid 的 RowChanged 事件没有相应

       解决:客户端代码中<LayoutSettings AllowAddNew="Yes" AllowDelete="Yes" AllowEdit="Yes" RowChangedAction="OnTheFlyPostback">

              </LayoutSettings>
               设置RowChangedAction="OnTheFlyPostback"


11 .客户端事件在哪里添加

解决:<LayoutSettings AllowAddNew="Yes" AllowDelete="Yes" AllowEdit="Yes" RowChangedAction="OnTheFlyPostback">

                                        <ClientSideEvents OnRowValidate="wgUserRole_OnRowValidate" />

                                        </LayoutSettings>

              ClientSideEvents 中可以添加客户端事件


12.WebGrid 的列内容唯一
          解决: 因为我们是通过 datatable 绑定的。。绑定前 DataColumn 设置列.Unique = true;

 

13.隐藏一列

解决:把改列的宽设置为 0px 或者 UltraWebGrid1.Columns[i].Hidden = true;

 

14.WebGrid在IE6和IE7中拖动错位解决办法:
  

 

二、项目应用

 

初始化

 

合并行

 

多表头

首先在UltraWebGrid中设置好列,这里默认设置的列是col1,col2_1,col2_2,col3.其中col2_1和col2_2是要生成多表头的列。
在UltraWebGrid的InitializeLayout事件中写如下代码:
// All the Headers for bound columns initialize to OriginX = 0.
// Since we want them
// to appear below the added column headers
//we are going to need to move them down a level
//先把所有列头都设为第二行
foreach (Infragistics.WebUI.UltraWebGrid.UltraGridColumn
 c in UltraWebGrid1.DisplayLayout.Bands[0].Columns)
{
 c.Header.RowLayoutColumnInfo.OriginY = 1;
//纵向起始点,0为第一行,1为第二行
}
//创建一个列头对象
var ch = new
Infragistics.WebUI.UltraWebGrid.ColumnHeader(true);
ch.Caption = "表头";   //列头文本标题
ch.RowLayoutColumnInfo.OriginX = 1;   //横向起始点,0为第一列,1为第二列
ch.RowLayoutColumnInfo.OriginY = 0;   //纵向起始点,0为第一行,1为第二行
ch.RowLayoutColumnInfo.SpanX = 2;   //设置横向跨度
e.DisplayLayout.HeaderStyleDefault.Height = Unit.Pixel(15);
e.Layout.Bands[0].HeaderLayout.Add(ch); //增加到列头集合中
//把非多表头的列,进行跨行
foreach (Infragistics.WebUI.UltraWebGrid.UltraGridColumn
c in e.Layout.Bands[0].Columns)
{
  if (c.Key != "col2_1" &amp;&amp; c.Key != "col2_2")
 //c.Key 非多表头列的key值
  {
   c.Header.RowLayoutColumnInfo.OriginY = 0; //从第一行开始
   c.Header.RowLayoutColumnInfo.SpanY = 2; //跨2行
   }
}
绑定数据源。只有在绑定数据源后,多表头格式才显示。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值