[英]how to get value of selected row in aspxgridview devexpress
我有一个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;
}
}
DevExpress在几乎所有控件中都使用了Callbacks ,这基本上有点像回发,但无需重新加载整个页面,而只是控件本身(在您的情况下,它将是ID为popupProductsGrid的ASPxGridView )。
因此,假设您只想使用回调,那么ASPxGridView的页面不会完全刷新,您将需要
实现此目的的最简单方法是使用FocusedRowChanged客户端事件触发所需的“单击”,然后从该调用PerformCallback将源对象属性GetFocusedRowIndex发送到服务器端,以便可以使用网格的GetRowValues方法在服务器端代码上( CustomCallback事件)
文档结尾处有一个很好的示例,它恰好可以实现您想要的ASPxGridView.CustomCallback事件 。
还要记住,要使回调能够根据需要工作,您需要将false设置为AutoPostBack属性,并将网格的EnableCallBacks属性设置为true(默认行为是使用回调而不是回发,但是请检查两个属性是否均已正确设置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.