浅谈Devpress之ASPxGridLookup使用方法

近项目中使用了DevPress控件,这些控件封装了一些特效,可以让我们少写很多js脚本。

这里只谈到ASPxGridLookup的简单web使用方式:

第一步:实现多选并在后台获取多选的值

 <dx:ASPxGridLookup ID="gridLookupAttendee" runat="server" SelectionMode="Multiple"
                        ClientInstanceName="gridLookupAttendee" KeyFieldName="Per_id" Width="79%" TextFormatString="{0}"
                        MultiTextSeparator=", " Height="21px">
                        <Columns>
                            <dx:GridViewCommandColumn ShowSelectCheckbox="True" />
                            <dx:GridViewDataColumn Caption="User Name" FieldName="Per_userName" />
                            <dx:GridViewDataColumn Caption="E_mail" FieldName="Per_email" Settings-AllowAutoFilter="False" />
                        </Columns>
                        <GridViewProperties>
                            <Templates>
                                <StatusBar>
                                    <table width="100%">
                                        <tr>
                                            <td style="width: 100%" />
                                            <td οnclick="return _aspxCancelBubble(event)">
                                                <dx:ASPxButton ID="Close" runat="server" AutoPostBack="false" Text="Close" ClientSideEvents-Click="CloseGridLookup" />
                                            </td>
                                        </tr>
                                    </table>
                                </StatusBar>
                            </Templates>
                            <Settings ShowFilterRow="True" ShowStatusBar="Visible" />
                        </GridViewProperties>
 </dx:ASPxGridLookup>

 属性解释:

 SelectionMode="Multiple/Single" 设置列表项是多选还是单选

 KeyFieldName="id"绑定数据源的主键字段

MultiTextSeparator=", " 设置文本显示格式可以用 逗号,分号,井号等

TextFormatString="{0}" 设置选择数据的显示格式 如 {0}-{1}

<dx:GridViewCommandColumn ShowSelectCheckbox="True" /> 下拉列表数据列是否显示复选框

<dx:GridViewDataColumn Caption="User Name" FieldName="Per_userName" /> 数据量绑定 类似GridView绑定Caption 展示名称,FieldName绑定的数据字段

<Settings ShowFilterRow="True" ShowStatusBar="Visible" /> 设置当前数据可以使用过滤查询功能

在 <GridViewProperties>中设置事件按钮      

在Script 脚本中添加

 function CloseGridLookup() {
            gridLookupAttendee.ConfirmCurrentSelection();
            gridLookupAttendee.HideDropDown();

        }  

第二步:从对象中赋值给ASPxGridLookup控件

当我们设置完前台界面后开始在后台实现取值过程

List<object> objList = this.gridLookupAttendee.GridView.GetSelectedFieldValues("Per_id");这句是获取在控件中选取的数据Id 并赋值给对象准备插入数据表
            if(objList!=null&&objList.Count>0)
            {
                string resStr=string.Empty;
                foreach (object item in objList)
                {
                    resStr += item.ToString() + ",";
                }
                
            }

如果我们因为业务需要 需要获取前台选择数据的多列值那就可以这样写

List<object> objList = this.gridLookupAttendee.GridView.GetSelectedFieldValues("Per_id","User_Name","Aage");括号里的字段要与你前台绑定数据源的字段相同,注意区分大小写

            if(objList!=null&&objList.Count>0)
            {
                string resStr=string.Empty;
                foreach (object[] item in objList)//当我们获取了多列值 就需要用Objec数据遍历了
                {
                    resStr += item[0].ToString() + item[1].ToString()+……;
                }               
            }

第三步:从数据源中查询数据复制到控件ASPxGridLookup

this.gridLookupAttendee.GridView.Selection.SetSelectionByKey(item, true);

item 是你的字段名称即可,如果是多选复制那就把你的数据源遍历用for循环

以上是控件使用三步骤 以供参考!谢谢!

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值