ASP.NET - 在gridview中添加一个UpdatePanel触发器到LinkButton [英] ASP.NET - Adding an UpdatePanel trigger to a LinkButton inside a gridview
问题描述
$ b
< asp: LinkButton ID =updateSomethingrunat =serverText =UpdateCausesValidation =falseOnClientClick =openDialog(); onclick =UpdateButton_Click/>
< asp:UpdatePanel ID =upNewUpdatePanelrunat =server>
< ContentTemplate>
< asp:Label ID =updateLabelrunat =server>< / asp:Label>
< / ContentTemplate>
<触发器>
< asp:AsyncPostBackTrigger ControlID =updateSomethingEventName =Click/>
< /触发器>
< / asp:UpdatePanel>
然而,当我尝试将LinkButton放置在gridview中时,像这样:
< asp:GridView ID =grdListUsersrunat =serverAutoGenerateColumns =falseAllowPaging =falseOnRowDataBound =grdRowDefListUsersCssClass =mGridEmptyDataText =没有用户。>
<列>
< asp:BoundField DataField =NameHeaderText =NomeHeaderStyle-Width =300/>
< asp:BoundField DataField =LoginHeaderText =LoginHeaderStyle-Width =300/>
< asp:TemplateField HeaderText =OptionsHeaderStyle-Width =75ItemStyle-HorizontalAlign =CenterItemStyle-VerticalAlign =Middle>
< ItemTemplate>
< asp:LinkButton ID =updateSomethingrunat =serverText =UpdateCausesValidation =falseOnClientClick =openDialog(); onclick =UpdateButton_Click/>
< / asp:TemplateField>
< /列>
< / asp:GridView>
这不起作用,我得到一个错误:一个ID为'updateSomething'的控件不能在UpdatePanel'upNewUpdatePanel'中找到触发器。
如何在gridview中使用ImageButton?
asp:AsyncPostBackTrigger
到 asp:GridView
的s OnRowCommand
事件并处理该事件中的链接按钮点击 < asp:GridView ID =grdListUsersrunat =serveronRowCommand =grdListUsers_RowCommand>
< asp:TemplateField>
< asp:LinkButton ID =updateSomethingCommandName =update-somethingCommandArgument ='<%#DataBinder.Eval(Container,RowIndex)%>'/>
< / asp:TemplateField>
< / asp:GridView>
并在cs中创建这样的事件
protected void grdListUsers_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName ==update-something)
{
grdListUsers.SelectedIndex = Convert.ToInt32(e.CommandArgument);
}
}
I was trying to update the content of a modal dialog, and this code works for me:
<asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />
<asp:UpdatePanel ID="upNewUpdatePanel" runat="server">
<ContentTemplate>
<asp:Label ID="updateLabel" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="updateSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
However, when I try to place the LinkButton inside a gridview, like so:
<asp:GridView ID="grdListUsers" runat="server" AutoGenerateColumns="false" AllowPaging="false" OnRowDataBound="grdRowDefListUsers" CssClass="mGrid" EmptyDataText="No users.">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Nome" HeaderStyle-Width="300" />
<asp:BoundField DataField="Login" HeaderText="Login" HeaderStyle-Width="300" />
<asp:TemplateField HeaderText="Options" HeaderStyle-Width="75" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:LinkButton ID="updateSomething" runat="server" Text="Update" CausesValidation="false" OnClientClick="openDialog();" onclick="UpdateButton_Click" />
</asp:TemplateField>
</Columns>
</asp:GridView>
This does not work, I get an error saying: A control with ID 'updateSomething' could not be found for the trigger in UpdatePanel 'upNewUpdatePanel'.
How can I use the ImageButton inside the gridview?
Try and add the asp:AsyncPostBackTrigger
to the asp:GridView
's OnRowCommand
event and handle the link button click in that event
<asp:GridView ID="grdListUsers" runat="server" onRowCommand="grdListUsers_RowCommand">
<asp:TemplateField>
<asp:LinkButton ID="updateSomething" CommandName="update-something" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'/>
</asp:TemplateField>
</asp:GridView>
and in the cs create the event like this
protected void grdListUsers_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "update-something")
{
grdListUsers.SelectedIndex = Convert.ToInt32(e.CommandArgument);
}
}
这篇关于ASP.NET - 在gridview中添加一个UpdatePanel触发器到LinkButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!