【问题标题】:how to get value of selected row in aspxgridview devexpress如何在 aspxgridview devexpress 中获取选定行的值
【发布时间】:2014-10-25 10:34:52
【问题描述】:

我有一个 devexpress aspxgridview,我需要获取所选行的值。有谁知道如何在不回发的情况下获取所选行的主键值。 OnSelectionChanged 事件不会被触发。如何在不回发的情况下触发 OnSelectionChanged 事件。

<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();
    }

还有一件事,我不希望它回发。所以我尝试了 HtmlRowPrepared 和 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;
        }
    }

【问题讨论】:

  • event doesnt get triggered。将AutoPostBack 设置为true.. ?
  • 但我不希望它回发。
  • 如果没有回发,它将不会被更新。你可以把它放在AjaxUpdatePanel,它会异步更新gridview

标签: c# asp.net gridview aspxgridview


【解决方案1】:

DevExpress 在他的几乎所有控件中都使用Callbacks,这些控件基本上有点像回发,但没有重新加载整个页面,只是控件本身(在您的情况下,它将是 ASPxGridView ID 为 popupProductsGrid)。

因此,假设您只想使用回调,因此您需要的 ASPxGridView 页面不会完全刷新

  1. 设置网格的ClientInstanceName属性(如popupProductsGrid)
  2. 处理 CustomCallback 事件(您已经在做)
  3. 每当用户单击一行时,在客户端使用 PerformCallback 函数(这样您就可以发送当前行索引,并从服务器端发送获取您需要的主键和其他行值)。

实现此目的的最简单方法是使用 FocusedRowChanged 客户端事件来触发您想要的“点击”并从该调用中触发 PerformCallback 将源对象属性 GetFocusedRowIndex 发送到服务器端,以便您可以使用 GetRowValues 服务器端代码网格的方法(CustomCallback 事件)

ASPxGridView.CustomCallback Event 的文档末尾有一个很好的示例,它完全符合您的要求。

还请记住,要让回调按您的意愿工作,您需要将 AutoPostBack 属性设置为 false,并将 EnableCallBacks 网格的属性(默认行为是使用回调而不是回发,但请检查两个属性是否设置正确)。

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-27
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多