触发 ASPxGridView RowClick 事件并在服务器上处理它

问题描述 投票:0回答:2

我有一个 ASPxGridView,它填充一些事务。

<dx:ASPxGridView ID="grdCapTrans" runat="server" ClientIDMode="AutoID" Width="100%"   EnableRowsCache="false">
</dx:ASPxGridView>

填充后,我想让用户自由选择行并查看单击行的详细信息。详细信息应显示在网格视图下方的文本框中。

如何在服务器上触发和处理?

c# asp.net devexpress
2个回答
0
投票

您可以使用

RowCommand event

链接:http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_RowCommandtopic

<dx:ASPxGridView ID="grid" 
runat="server" 
ClientInstanceName="grid" 
AutoGenerateColumns="false" 
onrowcommand="grid_RowCommand" >
   <Columns>
     <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" ButtonType="Button" />
   </Columns>
 </dx:ASPxGridView>

背后代码:

 protected void grid_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e)
 {
    ..... 
 }

绑定您的数据

grid.DataSource = ...;
grid.DataBind();

链接:http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_RowDeletingtopic


0
投票
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" >
     <Triggers>
     <asp:AsyncPostBackTrigger ControlID="cboTransType"   EventName="SelectedIndexChanged" />
     </Triggers>
        <ContentTemplate>
        <dx:ASPxGridView ID="grdCapTrans" runat="server" ClientIDMode="AutoID" Width="100%" EnableRowsCache="false" ClientInstanceName="grdCapTrans" onselectionchanged="grdCapTrans_SelectionChanged" 
        EnableCallBacks="false" KeyFieldName="ID" AutoGenerateColumns="false"> 
        <Columns>
        <dx:GridViewCommandColumn ShowInCustomizationForm="True" VisibleIndex="0" ButtonType="Button" ShowSelectCheckbox="true"> </dx:GridViewCommandColumn>
        <dx:GridViewDataTextColumn FieldName="ID" Name="ID" ShowInCustomizationForm="True" VisibleIndex="1"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="Description" Name="Description" ShowInCustomizationForm="True" VisibleIndex="2"></dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="Amount" Name="Amount" ShowInCustomizationForm="True" VisibleIndex="5"></dx:GridViewDataTextColumn> 
        <dx:GridViewDataTextColumn FieldName="Date" Name="Date" ShowInCustomizationForm="True" VisibleIndex="4"></dx:GridViewDataTextColumn>   
        <dx:GridViewDataTextColumn FieldName="Capturer" Name="Capturer" ShowInCustomizationForm="True" VisibleIndex="3"></dx:GridViewDataTextColumn>                                                                                    
        <dx:GridViewDataTextColumn FieldName="Status" Name="Status" ShowInCustomizationForm="True" VisibleIndex="6"></dx:GridViewDataTextColumn>                                                                                                                                                               

        </Columns>
        <SettingsBehavior ProcessSelectionChangedOnServer="true"  AllowFocusedRow="true" AllowSelectByRowClick="true" EnableRowHotTrack="true"    />

        </dx:ASPxGridView>
        <p>
        </p>
    </ContentTemplate>
    </asp:UpdatePanel>

背后代码

protected void grdCapTrans_SelectionChanged(object sender, EventArgs e)

{ 

    UpdatePanel1.Update();
    txtFullName.Text = grdCapTrans.GetSelectedFieldValues("Description")[1].ToString();

    message.InnerHtml = "Happy";


}

消息元素是一个 div,位于 updatepanel1 中。我希望在选择更改事件触发时显示消息“快乐”。令我惊讶的是,事实并非如此。

出了什么问题以及如何纠正。

© www.soinside.com 2019 - 2024. All rights reserved.