本文介绍了单击更新按钮时,Gridview不会刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,当我点击更新按钮时,它正在使用与之关联的sqldatasource更新数据库中的数据。但是像文本框,按钮这样的编辑字段并不令人耳目一新。当我单击取消按钮时,它只显示数据,文本框和更新按钮正在关闭和回发以编辑和删除按钮。



我的疑问是添加<$ p web.config文件中的$ p> MultipleActiveResultSets = True

这种变化是否会发生,因为上一页我有类似的gridview事件,但更改是按预期发生的。



我尝试了什么:



连接字符串:我删除了像数据库,初始目录用户名这样的公共语句和密码唯一一个MultipleActiveResultSets = True保存在这里

< connectionStrings> 
< add name =DefaultConnectionconnectionString =MultipleActiveResultSets = TrueproviderName =System.Data.SqlClient/>
< / connectionStrings>





我在updatepanel里面保留了这个gridview,其中up​​datemode =conditional和ChildrenAsTriggers =true



Gridview:

< asp:GridView ID =gvUsersListrunat =serverAutoGenerateColumns = FalseEmptyDataText =未找到记录AllowPaging =TrueGridLines =VerticalAlternatingRowStyle-CssClass =altSkinID =gridviewSkinWidth =100%CssClass =labelDataSourceID =userDetailsDataSourceDataKeyNames = 用户名 OnRowEditing = gvUsersList_RowEditing OnRowCancelingEdit = gvUsersList_RowCancelingEdit OnRowUpdating = gvUsersList_RowUpdating OnSelectedIndexChanged = gvUsersList_SelectedIndexChanged OnRowDeleting = gvUsersList_RowDeleting 
OnRowDataBound = gvUsersList_RowDataBound ShowHeaderWhenEmpty = 真正的
OnRow Command =gvUsersList_RowCommand
EnableViewState =false>
< asp:TemplateField ItemStyle-Width =250px>
< ItemTemplate>
< asp:Button ID =btnEditrunat =serverText =EditCssClass =btn btn-link text-centerToolTip =Edit User DetailsCommandName =EditUseSubmitBehavior = falseOnCommand =btnEdit_CommandOnClick =btnEdit_ClickCausesValidation =false/>

< asp:Button ID =btnDeleterunat =serverText =DeleteCssClass =btn btn-link text-centerToolTip =删除用户详细信息CommandName =删除UseSubmitBehavior =falseCausesValidation =falseOnClick =btnDelete_Click/>
< / ItemTemplate>
< HeaderStyle Width =50px/>
< EditItemTemplate>
< asp:Button ID =btnUpdaterunat =serverText =UpdateCommandName =UpdateCssClass =btn btn-linkUseSubmitBehavior =false/>
< asp:Button ID =btnCancelrunat =serverText =CancelCommandName =CancelUseSubmitBehavior =falseCssClass =btn btn-link/>
< / EditItemTemplate>
< / asp:TemplateField>
< / asp:GridView>





代码背后:

 if(!IsPostBack)
{
gvUsersList.DataSourceID =userDetailsDataSource;
gvUsersList.DataBind();
}
解决方案


My problem is when i click the update button it is updating the data in the database using sqldatasource associated with it. But the edit fields like textbox, buttons are not refreshing. When i click cancel button only it is showing the data and the textbox and update buttons are closing and postbacking to edit and delete buttons.

My doubt is adding

MultipleActiveResultSets=True

in web.config file this changes will be happened or not because previous page i had similar gridview event but the changes are happened as expected.

What I have tried:

Connection String: I have deleted the common statement like database, initial catalog username and password the only one MultipleActiveResultSets=True is kept here

<connectionStrings>
    <add name="DefaultConnection" connectionString="MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>



I have kept this gridview inside updatepanel having updatemode="conditional" and ChildrenAsTriggers="true"

Gridview:

<asp:GridView ID="gvUsersList" runat="server" AutoGenerateColumns="False" EmptyDataText="No Records Found" AllowPaging="True" GridLines="Vertical" AlternatingRowStyle-CssClass="alt" SkinID="gridviewSkin" Width="100%" CssClass="label" DataSourceID="userDetailsDataSource" DataKeyNames="UserID"                                            OnRowEditing="gvUsersList_RowEditing" OnRowCancelingEdit="gvUsersList_RowCancelingEdit"                                            OnRowUpdating="gvUsersList_RowUpdating" OnSelectedIndexChanged="gvUsersList_SelectedIndexChanged"                                            OnRowDeleting="gvUsersList_RowDeleting"
OnRowDataBound="gvUsersList_RowDataBound"                                             ShowHeaderWhenEmpty="true"
OnRowCommand="gvUsersList_RowCommand"
EnableViewState="false">
         <asp:TemplateField ItemStyle-Width="250px">
             <ItemTemplate>
                 <asp:Button ID="btnEdit" runat="server" Text="Edit" CssClass="btn btn-link text-center" ToolTip="Edit User Details" CommandName="Edit" UseSubmitBehavior="false" OnCommand="btnEdit_Command" OnClick="btnEdit_Click" CausesValidation="false" />

                 <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="btn btn-link text-center" ToolTip="Delete User Details" CommandName="Delete" UseSubmitBehavior="false" CausesValidation="false" OnClick="btnDelete_Click" />
            </ItemTemplate>
            <HeaderStyle Width="50px" />
            <EditItemTemplate>
                <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CssClass="btn btn-link" UseSubmitBehavior="false" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" UseSubmitBehavior="false" CssClass="btn btn-link" />
            </EditItemTemplate>
        </asp:TemplateField>
</asp:GridView>



Code Behind:

if (!IsPostBack)
{
    gvUsersList.DataSourceID = "userDetailsDataSource";
    gvUsersList.DataBind();
}
解决方案


这篇关于单击更新按钮时,Gridview不会刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:13