【发布时间】: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