如果满足某些条件,我会隐藏网格视图中的某个按钮:
protected void storyGridView_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int count = Int32.Parse(SqlInteraction.sqlQueryReturnString(conn => countNumberOfHoursBilled(conn, DataBinder.Eval(e.Row.DataItem, "PK_NonScrumStory").ToString())));
DateTime createdDate = DateTime.Parse(DataBinder.Eval(e.Row.DataItem, "CreatedDate").ToString());
if (count > 0 || createdDate < DateTime.Today)
{
Button btn = (Button)e.Row.FindControl("deleteButton");
btn.Visible = false;
}
else
{
Button btn = (Button)e.Row.FindControl("deleteButton");
btn.Visible = true;
}
}
}
这很好用,但我注意到在使用页面期间满足其中一个条件时,除非我刷新页面,否则删除按钮不会正确来回更改。
我试图对 gridview 进行数据绑定,但它不起作用;
protected void viewHoursGridView_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridView gv = sender as GridView;
SqlDataSource6.DeleteParameters["setDailyPKDeleteParam"].DefaultValue = gv.DataKeys[e.RowIndex].Value.ToString();
storyGridView.DataBind();
}
因此,如果我删除一行并且计数变为零,则该按钮应该是可见的。但在我刷新页面之前它不会变得可见。
我该如何解决?
编辑:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
SelectCommand="
SELECT NSS.PK_NonScrumStory
,SCY.Catagory AS Catagory
,APN.AppName AS [Application]
,NSS.IncidentNumber AS IncidentNumber
,CASE WHEN (NSS.[Status] = 1) THEN 'Open' ELSE 'Closed' END AS [Status]
,NSS.EstimatedHours AS EstimatedHours
,NSS.[Description] AS [Description]
,NSS.CreateDate AS CreatedDate
FROM NonScrumStory NSS
LEFT JOIN SupportCatagory SCY ON NSS.CatagoryId = SCY.PK_SupportCatagory
LEFT JOIN [Application] APN ON NSS.ApplicationId = APN.PK_Application
WHERE NSS.Deleted = 0
AND NSS.UserId = @nonScrumStoryUser
ORDER BY CreatedDate DESC
">
<SelectParameters>
<asp:QueryStringParameter Name="nonScrumStoryUser" Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>