本文介绍了如何让aspxgridview devex preSS选定行的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个devex preSS aspxgridview,我需要获取选中行的价值。有谁知道如何获得所选行的主键值不回发。 OnSelectionChanged事件犯规被触发。我怎样才能获得OnSelectionChanged事件,而不回发到被触发。

 < D​​X:ASPxGridView ID =popupProductsGrid=服务器的AutoGenerateColumns =FALSEWIDTH =815pxKeyFieldName =LOGICALREFClientInstanceName =popupProductsGrid
OnSelectionChanged =popupProductsGrid_SelectionChangedOnCustomCallback =popupProductsGrid_CustomCallback>
<柱体和GT;
    < D​​X:GridViewDataTextColumn标题=KOD字段名=URUNKODShowInCustomizationForm =真VisibleIndex =1WIDTH =100px的>
    < / DX:GridViewDataTextColumn>
    < D​​X:GridViewDataTextColumn标题=AÇIKLAMA字段名=URUNShowInCustomizationForm =真VisibleIndex =2WIDTH =250像素>
    < / DX:GridViewDataTextColumn>
    < D​​X:GridViewDataTextColumn标题=STOK字段名=MIKTARShowInCustomizationForm =真VisibleIndex =3WIDTH =50像素>
    < / DX:GridViewDataTextColumn>
    < D​​X:GridViewDataTextColumn标题=LOGICALREF字段名=LOGICALREFShowInCustomizationForm =真VisibleIndex =0可见=假WIDTH =100px的>
    < / DX:GridViewDataTextColumn>
    < D​​X:GridViewDataTextColumn标题=BİRİM字段名=ANABIRIMShowInCustomizationForm =真VisibleIndex =4WIDTH =40像素>
    < / DX:GridViewDataTextColumn>    < /专栏>
    < SettingsBehavior AllowFocusedRow =真AllowSelectByRowClick =真AllowSelectSingleRowOnly =真/>
    <设置ShowFilterRow =真/>
    < SettingsText EmptyDataRow =ListelenecekKayıtBulunamadı/>
    < / DX:ASPxGridView>
保护无效popupProductsGrid_SelectionChanged(对象发件人,EventArgs的发送)
    {
        DataRow的博士= popupProductsGrid.GetDataRow(popupProductsGrid.FocusedRowIndex);
        会话[stok_kodu] =博士[0]的ToString();
    }

还有一件事,我不希望它回发。所以,我想其他方法一样HtmlRow prepared和CustomCallback。

 保护无效popupProductsGrid_HtmlRow prepared(对象发件人,DevEx press.Web.ASPxGridView.ASPxGridViewTableRowEventArgs E)
    {
        如果(e.KeyValue!= NULL)
        {
            字符串参数= e.KeyValue.ToString();
            e.Row.Attributes.Add(的onclick,popupProductsGrid.PerformCallback('+参数+'));
        }
    }    保护无效popupProductsGrid_CustomCallback(对象发件人,DevEx press.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs E)
    {
        如果(e.Parameters!=)
        {
            会话[stok_kodu] = e.Parameters;
        }
    }


解决方案

DevEx preSS使用的的回调在几乎所有的控制它们基本上有点像回传,但没有重新加载整个页面只是控件本身(在你的情况下它会在 ASPxGridView 的ID popupProductsGrid)。

所以假设你希望只使用回调使网页不适合您的 ASPxGridView 您需要

刷新全部

  1. 设置 ClientInstanceName 栅格(如popupProductsGrid)的财产

  2. 处理在 CustomCallback 事件(你已经这样做)

  3. 使用 PerformCallback 。只要用户点击某行客户端功能(这样你就可以在服务器端发送当前行的索引,并从,你可以获得主键和其它行的值,你需要)。

最简单的方法来实现这一目标是使用 FocusedRowChanged 客户端事件触发了点击你想从该调用的 PerformCallback 发送源对象属性的 GetFocusedRowIndex 到服务器端,因此您可以使用 GetRowValues​​ 在服务器端code格的方法( CustomCallback 事件)

有在文件的结尾<一个很好的例子href=\"https://documentation.devex$p$pss.com/#AspNet/DevEx$p$pssWebASPxGridViewASPxGridView_CustomCallbacktopic\"相对=nofollow> ASPxGridView.CustomCallback事件这不正是你想要的。

还记得回调的工作,只要你想,你需要设置为false 的AutoPostBack 属性,并设置为true的 EnableCallBacks 的网格属性(默认行为是改用回发的回调,但检查两个属性都设置正确)。

I have a devexpress aspxgridview and I need to get the selected row's value. Does anyone know how to get the selected row's primary key value without postback. OnSelectionChanged event doesnt get triggered. How can I get the OnSelectionChanged event to be triggered without postback.

<dx:ASPxGridView ID="popupProductsGrid" runat="server" AutoGenerateColumns="False" Width="815px" KeyFieldName="LOGICALREF" ClientInstanceName="popupProductsGrid"
OnSelectionChanged="popupProductsGrid_SelectionChanged" OnCustomCallback="popupProductsGrid_CustomCallback">
<Columns>
    <dx:GridViewDataTextColumn Caption="KOD" FieldName="URUNKOD" ShowInCustomizationForm="True" VisibleIndex="1" Width="100px">
    </dx:GridViewDataTextColumn>
    <dx:GridViewDataTextColumn Caption="AÇIKLAMA" FieldName="URUN" ShowInCustomizationForm="True" VisibleIndex="2" Width="250px">
    </dx:GridViewDataTextColumn>
    <dx:GridViewDataTextColumn Caption="STOK" FieldName="MIKTAR" ShowInCustomizationForm="True" VisibleIndex="3" Width="50px">
    </dx:GridViewDataTextColumn>
    <dx:GridViewDataTextColumn Caption="LOGICALREF" FieldName="LOGICALREF" ShowInCustomizationForm="True" VisibleIndex="0" Visible="False" Width="100px">
    </dx:GridViewDataTextColumn>
    <dx:GridViewDataTextColumn Caption="BİRİM" FieldName="ANABIRIM" ShowInCustomizationForm="True" VisibleIndex="4" Width="40px">
    </dx:GridViewDataTextColumn>

    </Columns>
    <SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True" />
    <Settings ShowFilterRow="True" />
    <SettingsText EmptyDataRow="Listelenecek Kayıt Bulunamadı" />
    </dx:ASPxGridView>


protected void popupProductsGrid_SelectionChanged(object sender, EventArgs e)
    {
        DataRow dr = popupProductsGrid.GetDataRow(popupProductsGrid.FocusedRowIndex);
        Session["stok_kodu"] = dr[0].ToString();
    }

One more thing, I dont want it to postback. So I tried alternative ways like HtmlRowPrepared and CustomCallback.

  protected void popupProductsGrid_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
    {
        if (e.KeyValue != null)
        {
            string parameter = e.KeyValue.ToString();
            e.Row.Attributes.Add("onclick", "popupProductsGrid.PerformCallback('" + parameter + "')");
        }
    }

    protected void popupProductsGrid_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
    {
        if (e.Parameters != "")
        {
            Session["stok_kodu"] = e.Parameters;
        }
    }
解决方案

DevExpress uses Callbacks in almost all of his controls which are basically kinda like postbacks but without reloading the entire page just the control itself (in your case it will be the ASPxGridView with the ID popupProductsGrid).

So assuming that you want to use only callbacks so the page isn't entirely refreshed for your ASPxGridView you will need

  1. Set ClientInstanceName property of the grid (like popupProductsGrid)
  2. Handle the CustomCallback event (which you are already doing)
  3. Use the PerformCallback function on the client-side whenever a user clicks a row (so you can send the current row index and from that on the server side you can get the primary key and the other row values that you need).

The most easy way to achieve this is using the FocusedRowChanged client-side event to trigger the "on click" that you want and from that call PerformCallback sending the source object property GetFocusedRowIndex to the server side so you can use the GetRowValues method of the grid on the server side code (CustomCallback event)

There is a good example at the end of the documentation for ASPxGridView.CustomCallback Event which does exactly what you want.

Also remember that for callbacks to work as you want, you need to set to false the AutoPostBack property and set to true the EnableCallBacks property of the grid (default behavior is to use callbacks instead of postbacks but check that both properties are properly set).

这篇关于如何让aspxgridview devex preSS选定行的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:17