gpt4 book ai didi

c# - 仅在 Gridview 的最后一行显示复选框?

转载 作者:太空宇宙 更新时间:2023-11-03 11:43:29 24 4
gpt4 key购买 nike

是否可以有一个仅在编辑 GridView 的最后一行时显示的复选框?

我在 EditItemTemplate 中尝试过这样的事情:

<asp:CheckBox ID="chkNextDay" runat="server" 
ToolTip="Is it a next-day departure?"
Enabled="true"
Checked='<%# DateTime.Parse(Eval("OutHour","{0:d}")).Date >
DateTime.Parse(Eval("InHour","{0:d}")).Date %>'/>

然后在代码隐藏中,我尝试像这样隐藏最后一行以外的行:

protected void grvOutHour_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView grvOutHour = (GridView)this.grvReport.Rows[grvReport.EditIndex].FindControl("grvOutHour");
TextBox txtBox = (TextBox)grvOutHour.Rows[e.NewEditIndex].FindControl("txtEditOutHour");
CheckBox nextDay = (CheckBox)grvOutHour.Rows[e.NewEditIndex].FindControl("chkNextDay");
if (grvOutHour.Rows.Count-1 != e.NewEditIndex)
nextDay.Visible = false;
}

这几乎有效,但复选框一直显示所有字段,我认为是因为 RowDataBound 在 RowEditing 之后再次被调用,所以它再次呈现整个事物:(

有什么建议吗?

谢谢,伊顿公学。

最佳答案

改用 RowDataBound...

protected void grvOutHour_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
GridView grid = (GridView)sender;
CheckBox nextDay = (CheckBox)e.Row.FindControl("chkNextDay");
nextDay.Visible = (e.Row.RowIndex == (grid.Rows.Count - 1));
}
}

关于c# - 仅在 Gridview 的最后一行显示复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4025292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com