再淡netadvangate webdatagrid

现在再说关于webdatagrid的一些使用 写的不好或有错的地方望指出

这两天主要在做一个对webdatagrid的公用属性设置,大概就是设置下面的一些属性,比如列名,是否显示列,是否固定列列的宽度,还有列的排序和显示顺序。

 

 先说说编辑吧:webdatagrid启用编辑后,可以对单元格的内容进行编辑,需要设置DataKeyFields="ColumnKey"(表示唯一键,就像数据库表中的主键一样).如果单元格是绑定列,在触发了回发后(任何服务器控件的回发),就会对数据源进行更新,但如果数据源是datatable,dataset 或list 之类的话, 就会报错,具体原因不清楚,好像是因为回发会自动更新数据源,像这种不能找到连接来源的数据是更新不了的,所以报错。

 

解决办法是:添加一列非绑定列(unboundfields), 将绑定列设为隐藏列,在行初始化时为非绑列定赋值:

protected void WebDataGrid1_InitializeRow(object sender, RowEventArgs e)

{

//为非绑定列赋值

e.Row.Items.FindItemByKey("unboundfieldkey").Value = data;

 

//可以使用这种方法得到某单元格中的控件

CheckBox chkvisible = e.Row.Items.FindItemByKey("unboundfieldkey").FindControl("chkVisible") as CheckBox;

}

然后在保存的按钮事件就可以取得webdatagrid控件中的值再保存了。

Webdatagrid提供了很强大的编辑提供程序  提借单元格编辑时的样式 如编辑时显示为下拉框,日历时间,等。如   <EditorProviders>

                <ig:DropDownProvider ID="WebDataGrid1_DropDownProvider2">

                    <EditorControl ClientIDMode="Predictable" DropDownContainerMaxHeight="200px" EnableAnimations="False"

                        EnableDropDownAsChild="False" DropDownContainerHeight="70px">

                        <Items>

                            <ig:DropDownItem Selected="False" Text="顺3序¨°" Value="asc">

                            </ig:DropDownItem>

                            <ig:DropDownItem Selected="False" Text="倒Ì1序¨°" Value="desc">

                            </ig:DropDownItem>

                        </Items>

                    </EditorControl>

                </ig:DropDownProvider>

            </EditorProviders>

 

将WebDataGrid1_DropDownProvider2  这个ID关联到要编辑的列就行了 如下

  <Behaviors>

                <ig:EditingCore>

                    <Behaviors>

                        <ig:CellEditing>

                            <ColumnSettings>

                                <ig:EditingColumnSetting ColumnKey="unSortValue" EditorID="WebDataGrid1_DropDownProvider2" />

                            </ColumnSettings>

                        </ig:CellEditing>

                    </Behaviors>

                </ig:EditingCore>

            </Behaviors>

 

 

再说说前台操作吧:

   Webdatagrid在前台的操作也相当强大,可以通过jquery  $find("WebDataGrid1") 这样的方式得到这个控件

 

 需要注意几点:

1 $find("WebDataGrid1").get_rows().get_element().moveRow(fromrow, torow);

moveRow 方法是将几行移到到几行, 而这个行的值是生成的html的tr的index

jquery中可以用$(“tr”).index() 取得行号

在moveRow方法之后 其对应行的服务器行号的顺序并没有变, 不管此行显示在界面的第几行它在服务器的行号是不变的。 这点要注意。

 

  1. $find("WebDataGrid1").get_rows().get_row(index) 可以获取index对应的行,这个index 是用的服务器对应的行号

 

posted on 2012-02-29 12:34  安.  阅读(909)  评论(4编辑  收藏  举报

导航