如何在gridview中创建一个按钮会导致部分回发并更新我的面板 [英] How to make a button inside a gridview cause a partial post back and update my panel
问题描述
我有一个带有gridview的更新面板。 gridview包含一个按钮列。我希望每次单击此按钮时,都应刷新更新面板。从我能够实现的,buttton工作正常但我只能看到效果当我再次刷新整个页面。我需要在不刷新页面的情况下看到对click事件的影响。如何使这个gridview按钮导致部分回发
我尝试过:
i have an update panel with a gridview. The gridview consists of a button column. I want everytime this button is clicked, the update panel should be refreshed. From what i have been able to achieve, the buttton works fine but i would only be able to see the effect when i refreshed the whole page again. I need to see the effect on the click event without refreshing the page. How do i make this gridview button cause partial postback
What I have tried:
<pre lang="ASP.NET"><asp:TemplateField HeaderText="Action" Visible="True">
<ItemTemplate>
<asp:Button Visible='<%# string.IsNullOrEmpty(Eval("Signout_Time").ToString()) %>' ID="out" runat="server" Text="Sign out" CommandName="SignOut" CommandArgument='<%#Eval("SN") %>' ClientIDMode="AutoID"/>
</ItemTemplate>
</asp:TemplateField>
这是背后的代码。
This is the code behind.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button lb = e.Row.FindControl("out") as Button;
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);
}
}
这就是我点击按钮时的作用
this is what the button does when i click
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "SignOut")
{
string sN = e.CommandArgument.ToString();
reg.sn = int.Parse(sN);
string sign = System.DateTime.Now.ToString("yyyy-MM-dd:HH:mm:ss"); // get time out time
reg.signout = sign;
reg.SignOut(); // Save the signout time in db
整个过程结束后,我希望按钮只更新updatepanel。
After the whole process, i want the button to update only the updatepanel.
推荐答案
请参考
为ASP.Net中的AJAX UpdatePanel内的GridView内的LinkButton分配PostBack触发器(完全PostBack) [ ^ ]
这篇关于如何在gridview中创建一个按钮会导致部分回发并更新我的面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!