当前位置:编程学习 > C#/ASP.NET >>

高分求助,ASPxGridView 使用

ASPxGridView 在使用 DataItemTemplate 点页面任何按钮,会导致数据错乱
情境:
1.ASPxGridView 邦定数据
2.点ASPxGridView的其中有用到DataItemTemplate的例进行排序
3.点页面任何按钮,出现数据错乱(这时并没有触发重新读取数据.)

aspx代码
<dx:ASPxGridView ID="gvLicenseCost" runat="server" Width="100%" KeyFieldName="FUD_LicenseAdminSq"
  set AutoGenerateColumns="False" OnBeforeColumnSortingGrouping="gvLicenseCost_BeforeColumnSortingGrouping">
<Styles>
<AlternatingRow Enabled="true" />
<Header CssClass="tr_fixedrow" />
</Styles>
<SettingsText EmptyDataRow="<%$ Resources:Resource,ERPCTL1005000271%>" />
<SettingsPager Mode="ShowAllRecords" />
<SettingsLoadingPanel Mode="Disabled" />

<Columns>
<dx:GridViewDataTextColumn FieldName="LicenseCountry" VisibleIndex="1"      CellStyleHorizontalAlign="Left"
HeaderStyle-HorizontalAlign="Center" Caption="<%$ Resources:Resource,ERPFUD1002005031%>"
Width="9%">
<DataItemTemplate> <asp:Label ID="lblLicenseCountry" runat="server" Text='<%# Eval("LicenseCountry") %>'></asp:Label>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="FUD_LicenseAdminNm" VisibleIndex="2" CellStyle-HorizontalAlign="Center"
HeaderStyle-HorizontalAlign="Center" Caption="<%$ Resources:Resource,ERPCOM1002001691 %>"
Width="15%">
<DataItemTemplate> <asp:LinkButton ID="lbtnViewLicenseAdmin" runat="server" Text='<%# Eval("FUD_LicenseAdminNm") %>' OnClientClick="OpenDetail(this);return false;"></asp:LinkButton> <asp:HiddenField ID="hidLicenseAdminSq" runat="server" Value='<%# Eval("FUD_LicenseAdminSq") %>' />
</DataItemTemplate>
</dx:GridViewDataTextColumn>
  </Columns>
</dx:ASPxGridView>
--------------------编程问答--------------------

<dxwgv:ASPxGridView ID="gvAdjust" ClientInstanceName="gvAdjust" KeyFieldName="Guid" runat="server" Width="100%" AutoGenerateColumns="False">
    <Columns>
        <dxwgv:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" Visible="false">
            <HeaderTemplate>
                 <input type="checkbox" onclick="gvAdjust.SelectAllRowsOnPage(this.checked);" title="选择/取消选择" style="vertical-align:middle;"></input>
             </HeaderTemplate>
            <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" HorizontalAlign="Center">
                <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
            </HeaderStyle>
        </dxwgv:GridViewCommandColumn>
        <dxwgv:GridViewDataCheckColumn Caption="审核" FieldName="YS" Width="30px" VisibleIndex="1">
        </dxwgv:GridViewDataCheckColumn>
        <dxwgv:GridViewDataTextColumn Caption="单据编号" FieldName="DJBH" VisibleIndex="2">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="业务日期" FieldName="RQ" VisibleIndex="3">
            <PropertiesTextEdit DisplayFormatString="yyyy-MM-dd"></PropertiesTextEdit>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="调整类型" FieldName="LXMC" VisibleIndex="4">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="仓库" FieldName="CKMC" VisibleIndex="5">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="制单人" FieldName="ZDR" VisibleIndex="6"></dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="制单日期" FieldName="ZDRQ" VisibleIndex="7">
            <PropertiesTextEdit DisplayFormatString="yyyy-MM-dd"></PropertiesTextEdit>
        </dxwgv:GridViewDataTextColumn>
    </Columns>
    <ClientSideEvents RowDblClick="view" />
    <Settings ShowFilterRow="false" ShowVerticalScrollBar="True" VerticalScrollableHeight="347"/>
    <SettingsBehavior AllowFocusedRow="true" />
    <SettingsPager PageSize="50" Visible="False" />
</dxwgv:ASPxGridView>



protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.cboCANGKU.DataSource = new CANGKU().GetList(new QueryCondition() { FieldName = "TY", Comparison = "=", Value = "0" });
            this.cboCANGKU.DataBind();
            this.cboTZLX.DataSource = new KCTZLX().GetList(new QueryCondition() { FieldName = "IS_TY", Comparison = "=", Value = "0" });
            this.cboTZLX.DataBind();
            this.cboCANGKU.Items.Insert(0, new DevExpress.Web.ASPxEditors.ListEditItem("", "-1"));
            this.cboTZLX.Items.Insert(0, new DevExpress.Web.ASPxEditors.ListEditItem("", "-1"));
            this.cboCANGKU.SelectedIndex = 0;
            this.cboTZLX.SelectedIndex = 0;
            this.cboYS.SelectedIndex = 0;
        }
        if (!IsPostBack || this.gvAdjust.IsCallback || Common.IsExport)
        {
            BindData();
        }
    }

    private void BindData()
    {
        List<QueryCriteria> condition = new List<QueryCriteria>();
        if (!string.IsNullOrEmpty(this.deBeginDate.Text))
        {
            condition.Add(new QueryCriteria() { FieldName = "RQ", Comparison = EnumSqlComparison.LargerEqualThan, Value = this.deBeginDate.Date.ToString("yyyy-MM-dd 00:00:00") });
        }
        if (!string.IsNullOrEmpty(this.deEndDate.Text))
        {
            condition.Add(new QueryCriteria() { FieldName = "RQ", Comparison = EnumSqlComparison.LessEqualThan, Value = this.deEndDate.Date.ToString("yyyy-MM-dd 23:59:59") });
        }
        if (!string.IsNullOrEmpty(this.txtDJBH.Text))
        {
            condition.Add(new QueryCriteria() { FieldName = "DJBH", Comparison = EnumSqlComparison.Like, Value = this.txtDJBH.Text.Replace("'", "''") });
        }
        if (!this.cboTZLX.Value.Equals("-1"))
        {
            condition.Add(new QueryCriteria() { FieldName = "LXMC", Comparison = EnumSqlComparison.Like, Value = this.cboTZLX.Text.Replace("'", "''") });
        }
        if (!this.cboCANGKU.Value.Equals("-1"))
        {
            condition.Add(new QueryCriteria() { FieldName = "CKMC", Comparison = EnumSqlComparison.Like, Value = this.cboCANGKU.Text.Replace("'", "''") });
        }
        if (!this.cboYS.Value.Equals("-1"))
        {
            condition.Add(new QueryCriteria() { FieldName = "YS", Comparison = EnumSqlComparison.Equal, Value = this.cboYS.Value.ToString() });
        }
        this.ASPxPager1.ItemCount = new V_CKTZD().GetCount(condition);
        this.gvAdjust.DataSource = new V_CKTZD().GetList(condition, this.ASPxPager1.PageIndex + 1).OrderByDescending(p => p.ZDRQ);
        this.gvAdjust.DataBind();
    }

    protected void ASPxPager1_PageIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }

    public void Query()
    {
        if (this.ASPxPager1.PageIndex != 0) this.ASPxPager1.PageIndex = 0;
        BindData();
    }

--------------------编程问答-------------------- 参考

注意样式
<Styles>
<Header HorizontalAlign="Center" />      : 标题居中对齐
<AlternatingRow Enabled="true"/>         : 交错行效果
<CommandColumn Paddings-Padding="1" />   : 
</Styles>

--------------------编程问答-------------------- 用法和DataGrid有什么区别吗?

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        DataTable table = GetDataTable();
        
        this.DataGridList.DataSource =ModelList;
        this.DataGridList.DataBind();
    }

--------------------编程问答-------------------- 看看是不是格式写的问题 --------------------编程问答--------------------  

 <!--search end-->
                    <dx:ASPxGridView ID="ASPxGridViewCustomerList" DataSourceID="SqlDataSourceCustomerList"
                        runat="server" OnHtmlDataCellPrepared="ASPxGridViewCustomerList_HtmlDataCellPrepared"
                        KeyFieldName="KHBH" AutoGenerateColumns="False" ClientIDMode="AutoID" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                        CssPostfix="Aqua" Width="100%">
                        <Columns>
                            <dx:GridViewDataHyperLinkColumn Caption="客户名称" FieldName="KHBH" VisibleIndex="0"
                                ReadOnly="true">
                                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/Visit/CustomerView.aspx?KHBH={0}"
                                    TextField="XM" Target="_blank">
                                </PropertiesHyperLinkEdit>
                                <Settings SortMode="DisplayText" FilterMode="DisplayText" AllowSort="True" />
                                <CellStyle Wrap="false">
                                </CellStyle>
                            </dx:GridViewDataHyperLinkColumn>
                            <dx:GridViewDataTextColumn Caption="所属公司名称" FieldName="GSMC" VisibleIndex="1">
                                <Settings AllowSort="True" FilterMode="DisplayText" SortMode="DisplayText" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="固定电话" FieldName="GDDH" VisibleIndex="3">
                                <Settings AllowSort="True" FilterMode="DisplayText" SortMode="DisplayText" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="移动电话" FieldName="YDDH" VisibleIndex="4">
                                <Settings AllowSort="True" FilterMode="DisplayText" SortMode="DisplayText" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="传真" FieldName="CZ" VisibleIndex="5">
                                <Settings AllowAutoFilter="False" AllowSort="True" SortMode="DisplayText" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="客户分类" FieldName="KHFL" VisibleIndex="6">
                                <Settings AllowAutoFilter="False" AllowSort="True" SortMode="DisplayText" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="编辑人名称" FieldName="YHMC" VisibleIndex="8">
                                <Settings AllowSort="True" FilterMode="DisplayText" SortMode="DisplayText" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataTextColumn Caption="编辑时间" FieldName="BJSJ" VisibleIndex="9">
                                <Settings AllowAutoFilter="False" AllowSort="True" FilterMode="DisplayText" SortMode="DisplayText" />
                            </dx:GridViewDataTextColumn>
                            <dx:GridViewDataHyperLinkColumn Caption="编辑" FieldName="KHBH" VisibleIndex="10" ReadOnly="True">
                                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/Visit/CustomerRegister.aspx?KHBH={0}"
                                    Text="编辑" Target="_blank">
                                </PropertiesHyperLinkEdit>
                                <Settings SortMode="DisplayText" AllowAutoFilter="False" />
                                <Settings SortMode="DisplayText" />
                                <Settings SortMode="DisplayText" />
                                <CellStyle Wrap="False">
                                </CellStyle>
                            </dx:GridViewDataHyperLinkColumn>
                            <dx:GridViewCommandColumn VisibleIndex="11" Caption="操作">
                                <DeleteButton Visible="True" Text="删除">
                                </DeleteButton>
                                <ClearFilterButton Visible="True">
                                </ClearFilterButton>
                            </dx:GridViewCommandColumn>
                        </Columns>
                        <SettingsBehavior AllowDragDrop="False" AllowSort="true" />
                        <SettingsBehavior ConfirmDelete="true" />
                        <Settings ShowFilterRow="True" />
                        <SettingsText ConfirmDelete="确定要删除吗?" />
                        <SettingsPager PageSize="15">
                        </SettingsPager>
                        <SettingsLoadingPanel ImagePosition="Top" />
                        <SettingsLoadingPanel ImagePosition="Top" />
                        <SettingsLoadingPanel ImagePosition="Top" />
                        <Images SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css">
                            <LoadingPanelOnStatusBar Url="~/App_Themes/Aqua/GridView/gvLoadingOnStatusBar.gif">
                            </LoadingPanelOnStatusBar>
                            <LoadingPanel Url="~/App_Themes/Aqua/GridView/Loading.gif">
                            </LoadingPanel>
                        </Images>
                        <ImagesEditors>
                        <StylesEditors>
                            <CalendarHeader Spacing="1px">
                            </CalendarHeader>
                            <ProgressBar Height="25px">
                            </ProgressBar>
                        </StylesEditors>
                    </dx:ASPxGridView>
                    <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="0">
                        <ProgressTemplate>
                            <asp:Image ID="UpdateProgressImage" runat="server" ImageUrl="~/images/loading.gif"
                                Style="position: absolute; left: 50%; top: 50%;" />
                        </ProgressTemplate>
                    </asp:UpdateProgress>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:SqlDataSource ID="SqlDataSourceCustomerList" runat="server" ConnectionString="<%$ ConnectionStrings:CMSPMSDBConnectionString %>"
                DeleteCommand="PKG_CUSTOMERINFO.P_DELCUSTOMER" DeleteCommandType="StoredProcedure"
                ProviderName="<%$ ConnectionStrings:CMSPMSDBConnectionString.ProviderName %>"
                SelectCommand="PKG_CUSTOMERINFO.P_QUERYCUSTOMERINFOLIST" SelectCommandType="StoredProcedure"
                OnDeleting="SqlDataSourceCustomerList_Deleting" OnSelecting="SqlDataSourceCustomerList_Selecting">
                <DeleteParameters>
                    <asp:Parameter Name="v_khbh" Type="String" />
                    <asp:Parameter Name="v_czr" Type="String" />
                </DeleteParameters>
                <SelectParameters>
                    <asp:Parameter Name="v_yhbh" Type="String" />
                    <asp:Parameter Name="v_khxm" Type="String" />
                    <asp:Parameter Name="v_ssgsbh" Type="String" />
                    <asp:Parameter Name="v_cxlx" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div>
        <!--mainbox_c end-->
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,