Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在UpdatePanel中使用GridView_C#_Asp.net_Asp.net Ajax_Updatepanel - Fatal编程技术网

C# 在UpdatePanel中使用GridView

C# 在UpdatePanel中使用GridView,c#,asp.net,asp.net-ajax,updatepanel,C#,Asp.net,Asp.net Ajax,Updatepanel,我有一个Updatepanel和Gridview在里面 <asp:UpdatePanel ID="uplPanel" UpdateMode="Conditional" runat="server" OnLoad="uplPanel_Load"> <ContentTemplate> <asp:GridView ID="gvPrList" runat="server" AutoGenerateColumns="false" AllowPaging="false"

我有一个Updatepanel和Gridview在里面

<asp:UpdatePanel ID="uplPanel" UpdateMode="Conditional" runat="server" OnLoad="uplPanel_Load">
<ContentTemplate>
 <asp:GridView ID="gvPrList" runat="server" AutoGenerateColumns="false" AllowPaging="false"
       AllowSorting="false" CssClass="list-table" HeaderStyle-CssClass="header">
       <Columns>
     <ItemTemplate>
               <asp:Button ID="btnEdit" runat="server" Text="Edit" CssClass="button save" OnCommand="onPrItemCmd"
                   CommandName="editRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" />
               <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="button save" OnCommand="onPrItemCmd"
                   CommandName="deleteRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" />
           </ItemTemplate>
       </asp:TemplateField>
   </Columns>

当我点击Griview中的按钮时,它不会触发事件。
有什么想法吗?

您需要在GridView的命令上添加

OnRowCommand="gvPrList_OnRowCommand" 
或者,为单个按钮添加单击事件,然后在代码隐藏文件中处理:

<asp:Button ID="btnEdit" runat="server" OnClick="btnEdit_Click" Text="Edit" CssClass="button save"
                   OnCommand="onPrItemCmd" CommandName="editRow" CommandArgument='<%#Bind("ID") %>' Style="width: 80px" />

这将是codebehind中命令的事件处理程序:

protected void onPrItemCmd(object sender, CommandEventArgs e)
    {
        //do whatever you want
        //probably you will need the "ID" or "CommandArgument":
        string myArgumentID = e.CommandArgument.ToString();

        uplPanel.Update(); //since the UpdatePanel is set *UpdateMode="Conditional"*
    }
更新:


当您单击按钮时,可能正在进行一些验证。如果是这样,您需要在按钮或链接属性中添加CausesValidation=“false”,请将此代码添加到UpdatePanel中

</ContentTemplate> 
 <Triggers>
   <asp:PostBackTrigger ControlID="gvPrList" EventName="Click" />
 </Triggers>
 </asp:UpdatePanel>

我做了以下操作,效果很好

我将asp按钮替换为html按钮,并调用javascript方法来触发Update Panal Load事件

<input id="btnDelete1" type="button" onclick="javascript:DeletePrItem('<%# Eval("ID") %>');" value="Delete" class="button save" style="width: 80px" />

我遇到了同样的问题,带有OnClick的列按钮导致回发,但是OnClick方法没有被命中。当我注释掉更新面板时,一切都正常了

我通过在更新面板中为网格添加回发触发器解决了此问题:

</ContentTemplate>
   <Triggers>
       <asp:PostBackTrigger ControlID="uxWebDataGrid" />
   </Triggers>
</asp:UpdatePanel>


希望这对其他人有帮助

我添加了OnRowCommand事件,并将此触发器添加到UpdatePanel:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="gvPrList" EventName="RowCommand" />
</Triggers>

请注意,这是一个异步触发器。

我也有类似的问题

取决于你的情况,就像我一样……更新面板内的所有可点击控件我都想成为触发器;所以我可以简单地使用UpdatePanel属性'ChildrenAsTriggers=“true”'来解决这个问题

    <asp:UpdatePanel runat="server" ID="UPCommunicationlogForm" ChildrenAsTriggers="true" >

这解决了我的问题,现在从gridview中的ItemTemplate生成的编辑和删除按钮在服务器上调用各自的方法。

这对我有帮助。 在我的例子中,我更改了asp:DropDownList控件中的一个值,然后返回到服务器更新另一个asp:UpdatePanel中的asp:GridView。我只是忘了添加代码来用列表刷新更新面板。一旦我做到了,一切都很顺利

服务器端

System.Data.DataSet ds = MySQL.DAL.GetRecord(sql);
GV_View.DataSource = ds;
GV_View.DataBind();
UP_MainList.Update(); //refresh the update panel
Aspx代码

            <asp:UpdatePanel runat="server" ID="UP_ListChange" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:DropDownList runat="server" ID="ddFilter" DataTextField="Desc" AutoPostBack="true" DataValueField="Detail" OnSelectedIndexChanged="GV_CodeView_RefreshScreen" ></asp:DropDownList>
                </ContentTemplate>
             </asp:UpdatePanel>
            <div class="medium">Select Filter to view database codes</div>
        </div>
        <div class="div-row-header" runat="server" id="divList">
        <asp:UpdatePanel runat="server" ID="UP_MainList" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="GV_View" runat="server" AllowSorting="True" AutoGenerateColumns="false" DataKeyNames="id">
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="Id" Visible="false" />
                    <asp:BoundField DataField="Type_Cd" HeaderText="Code" />
                    <asp:BoundField DataField="Short_Desc" HeaderText=" Description" />
                    <asp:TemplateField HeaderText="">
                        <ItemTemplate>
                            <asp:Button ID="Code_Edit" runat="server" Text="Edit" onClick="GV_Code_Edit_Click" class="button" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>             
        </ContentTemplate>

        </asp:UpdatePanel>
        </div>

选择过滤器以查看数据库代码

谢谢。我已经有了onPrItemCmd事件的代码隐藏处理程序方法。您是否尝试将
onclick
事件处理程序添加到按钮,然后检查其是否有效???我收到以下错误:键入“System.Web.UI.PostBackTrigger”没有名为“EventName”的公共属性。我正在使用asp.net 3.5受保护的无效单击(对象发送者,CommandEventArgs e){}//创建这是一个虚拟事件,然后尝试“System.Web.UI.PostBackTrigger”没有此属性如果它是
PostBackTrigger
,它不需要事件-只有
AsyncPostBackTrigger
需要。@Nilaa只是想知道为什么要使用OnLoad=“uplPanel\u Load”?你在做什么?这是一项非常简单的任务,而且很奇怪,它没有触发事件。这也是一个好主意,从头创建页面,看看它在哪里打破…我有一些其他按钮调用sharepoint模型弹出窗口。使用“doPostBack”('','');也许这就是问题的原因。有什么想法吗?我尝试过使用它,得到了异常
在渲染之前只能在ID为'UpdatePanel1'的UpdatePanel上调用Update方法
@vapcguy尝试用UpdatePanel1替换UplpPanel,UpdatePanel1是更新面板的标识符……。@aleafonso
UpdatePanel1
是我的标识符<代码>上传面板
是OP的标识符。不管我叫什么,这都是我想说的——只是表明这是同一个场景,当你在.NET不喜欢的地方调用
.Update()
时会出现错误(比如按钮单击事件)。不过,我设法以一种与这篇文章无关的方式解决了我的问题。我有一个计时器作为更新面板的触发器,我的按钮单击事件启用计时器。我将数据表的
.DataBind()
放在我的
Timer1\u Tick()
函数的gridview中,没有
.Update()
System.Data.DataSet ds = MySQL.DAL.GetRecord(sql);
GV_View.DataSource = ds;
GV_View.DataBind();
UP_MainList.Update(); //refresh the update panel
            <asp:UpdatePanel runat="server" ID="UP_ListChange" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:DropDownList runat="server" ID="ddFilter" DataTextField="Desc" AutoPostBack="true" DataValueField="Detail" OnSelectedIndexChanged="GV_CodeView_RefreshScreen" ></asp:DropDownList>
                </ContentTemplate>
             </asp:UpdatePanel>
            <div class="medium">Select Filter to view database codes</div>
        </div>
        <div class="div-row-header" runat="server" id="divList">
        <asp:UpdatePanel runat="server" ID="UP_MainList" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="GV_View" runat="server" AllowSorting="True" AutoGenerateColumns="false" DataKeyNames="id">
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="Id" Visible="false" />
                    <asp:BoundField DataField="Type_Cd" HeaderText="Code" />
                    <asp:BoundField DataField="Short_Desc" HeaderText=" Description" />
                    <asp:TemplateField HeaderText="">
                        <ItemTemplate>
                            <asp:Button ID="Code_Edit" runat="server" Text="Edit" onClick="GV_Code_Edit_Click" class="button" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>             
        </ContentTemplate>

        </asp:UpdatePanel>
        </div>