简体   繁体   English

我们可以避免在gridView中回发吗……当用户单击其中的一个按钮时?

[英]Can we avoid postback in gridView…when user click a button in same?

I have a gridview ...in my dotnet 2.0 - web application. 我在dotnet 2.0-Web应用程序中有一个gridview。

gridview has 2 columns...first column is ID..and second is a "link button"..as shown below. gridview有2列...第一列是ID ..第二列是“链接按钮” ..如下所示。

On click of this link, I have to display a popup..and I'm using ajax ModalPopupExtender. 在单击此链接时,我必须显示一个弹出窗口。并且我正在使用ajax ModalPopupExtender。

I am able to see the popup. 我可以看到弹出窗口。

But the issue is...when I click on this link button the postback happens...and the gridview.datasource is NULL. 但是问题是...当我单击此链接按钮时发生回发...并且gridview.datasource为NULL。 So I have to fetch the data from database and bind the gridview again. 因此,我必须从数据库中获取数据并再次绑定gridview。

Please help me to find a way to avoid this. 请帮助我找到避免这种情况的方法。

<asp:GridView ID="AvailableGridView" >
<Columns>
<asp:BoundField ItemStyle-CssClass="ItemStyleCss" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="GridHeaderRow" HeaderText="ID" DataField="ClaimCodeGroupIdText"
/>
     <asp:TemplateField HeaderText="View" ShowHeader="False">                                                                                <ItemTemplate>
               <asp:LinkButton  CssClass="localNavigation" ID="ViewCCGLinkButton"         
       Text="View" CommandName="View"                                                                          CommandArgument='<%# Eval("ClaimCodeGroupId") %>' runat="server"></asp:LinkButton>
            </ItemTemplate>
       <ItemStyle HorizontalAlign="Center" />
     <HeaderStyle CssClass="GridHeaderRow" />
    </asp:TemplateField>

</Columns>
<asp:GridView />

You can set ajax toolkit modal popup to load client side and not cause a postback. 您可以设置ajax工具箱模式弹出窗口以加载客户端,而不引起回发。

But if you have to get data from the server side, i think you have following options 但是,如果您必须从服务器端获取数据,我认为您有以下选择

  1. Use ajax to load server data 使用Ajax加载服务器数据
  2. Save the selected Id in the hidden text box and on postback read Id thru hidden textbox 将所选ID保存在隐藏文本框中,并在回发时通过隐藏文本框读取ID
  3. Use jQuery BlockUI and ajax to load server data (personal fav.) 使用jQuery BlockUI和Ajax加载服务器数据(个人收藏)

Pick your options according to ur need and requirement. 根据您的需求和要求选择您的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM