ASPxGridView的FocusedRowChanged

来源:互联网 发布:java http服务器框架 编辑:程序博客网 时间:2024/06/08 06:02
 

最近一直在用Developer Express的这套控件,在使用ASPxGridView 是想触发服务器端FocusedRowChanged事件,以及客户端javascript的FocusedRowChanged事件,2者之间的设置区别,网上找了很长时间发现网上有相关的文章,按照作者写的设置发现有点问题,特此总结一下

 一:关于ASPxGridView控件触发服务器端FocusedRowChanged事件的设置

(1)<dxwgv:ASPxGridView ID="gdDhdList" runat="server"  Width="100%"  AutoGenerateColumns="true" 
                        KeyFieldName="shp_id_from"  EnableCallBacks="False" //允许触发服务器端事件gdDhdList_FocusedRowChanged,而且禁止调用javascript的回传函数,也就是不触发客户端javascript的FocusedRowChanged函数 
                     onfocusedrowchanged="gdDhdList_FocusedRowChanged">//指定服务器端事件

(2)

<SettingsBehavior AllowSort="False"  AllowFocusedRow="True"  // 允许选中行

                                                                 ProcessFocusedRowChangedOnServer="True" />// 默认为false,当选中不同焦点行,允许触发服务器端事件gdDhdList_FocusedRowChanged,而且禁止调用javascript的回传函数,也就是不触发客户端javascript的FocusedRowChanged函数 

(3)//服务器端事件

        protected void gdDhdList_FocusedRowChanged(object sender, EventArgs e)
        {
          
  try
            {     //获取选中焦点行,指定字段的值
                string focusShpID = Hanson.DataConvert.ToString(this.gdDhdList.GetRowValues(this.gdDhdList.FocusedRowIndex, "shp_id_from"));               

            }
            catch (Exception)
            {
                throw;
            }
        }

二:关于ASPxGridView控件触发客户端javascript的FocusedRowChanged函数的设置

(1)设置ASPxGridView属性:

<dxwgv:ASPxGridView ID="gdDhdList" runat="server"  Width="100%"ClientInstanceName="DatList"   //js客户端获取的对象
                        AutoGenerateColumns="true"   //true:可以按照将后台绑定数据源的列绑定控件,//false:代表不能将后台绑定数据源的列绑定控件,此时一般都在界面上指定列。
                        KeyFieldName="shp_id_from"  EnableCallBacks="True" >//允许调用javascript的回传函数,禁止 触发服务器端gdDhdList_FocusedRowChanged事件

            <SettingsBehavior AllowSort="False"  AllowFocusedRow="True"   // 允许选中行
 ProcessSelectionChangedOnServer="False"
/>//默认为false,当选中不同焦点行,允许调用javascript的函数,
也就是触发客户端javascript的FocusedRowChanged函数 ,而且禁止触发服务器端事件gdDhdList_FocusedRowChanged

             <ClientSideEvents FocusedRowChanged="function(s, e) { OnGridFocusedRowChanged(); }" />   //指定FocusedRowChanged函数

(2)javascript函数:

 <script type="text/javascript">
        function OnGridFocusedRowChanged() {
            DatList.GetRowValues(DatList.GetFocusedRowIndex()
            , 'fas_id;fas_pic'       //多个字段之间用分号;隔开,如果只有一个字段要有分号;结束
            , OnGetRowValues); //获取对应字段的值的回调函数
        }


        function OnGetRowValues(values) {
            var fasID = values[0];    //  与字段索引取值
            var fasPic = values[1];     

     window.iAction.location.href ="FashionInfo.aspx?fasID="+ fasID ;

        }

但是,还有一个问题,就是在点击分页按钮时,没有触法该事件OnGridFocusedRowChanged,需要另加判断获取。或者不分页显示所有行<SettingsPager Mode="ShowAllRecords">。