使用字符串切换 itemtemplate 中的可见状态
我有在 gridview 中显示的数据。如果我从一个表中提取它,我希望它是读/写的,但从另一个表中只是读取。我有一个 SqlDataSource 可以根据来源吐出一些文本,是的,它吐出的文本是准确的。因此,我在 gridview 的 itemtemplate 中放置了一个标签和一个文本框,并且两者的可见属性都设置为公共 bool。
问题是这并不总是一致的。有时,一个属性的数据会切换到另一种形式(即,只读数据显示为文本框),但并非每次都会如此,因此这不是一个简单的“搞砸了我的 if 语句”问题。显示状态通常与显示的文本相反。
<asp:TemplateField HeaderText="Next Price" SortExpression="newdata">
<ItemTemplate>
<asp:TextBox ID="ReadWrite" runat="server"
Text='<%# Bind("newdata", "{0:N2}") %>' Width="60px"
class="calculate" onchange="calculate()"
Visible='<%# ShowBox %>'></asp:TextBox>
<asp:Label ID="ReadOnly" runat="server" Text='<%# Bind("newdata", "{0:N2}") %>'
Visible='<%# ShowLabel %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
其背后的代码:
protected void MasterDisplay_DataBound(object sender, EventArgs e)
{
DataSourceSelectArguments sr = new DataSourceSelectArguments();
DataView dv = (DataView)CheckForCommit.Select(sr);
if (dv.Count != 0)
CommittedOrNot.Text = dv[0][0].ToString();
//for displaying where data is pulled from
}
public bool ShowBox
{
get
{
return (CommittedOrNot.Text == "This has not yet been committed.");
}
private set { }
}
public bool ShowLabel
{
get { return (CommittedOrNot.Text != "This has not yet been committed."); }
private set { }
}
有什么想法导致这种脱节吗?
I have data that gets displayed in gridview. If I'm pulling it from one table I want it to be read/write, but from the other just read. I have a SqlDataSource that can spit out some text based on the origin, and yes the text it spits out is accurate. So I put a label and a textbox in an itemtemplate in gridview, and both have visible properties set to a public bool.
The problem is that this doesn't always line up. Sometimes on data of one property switches to the other form (ie, read-only data is displayed as a textbox), but it's not everytime so it's not a simple "screwed up my if statement" problem. The display state will often be the opposite of the displayed text.
<asp:TemplateField HeaderText="Next Price" SortExpression="newdata">
<ItemTemplate>
<asp:TextBox ID="ReadWrite" runat="server"
Text='<%# Bind("newdata", "{0:N2}") %>' Width="60px"
class="calculate" onchange="calculate()"
Visible='<%# ShowBox %>'></asp:TextBox>
<asp:Label ID="ReadOnly" runat="server" Text='<%# Bind("newdata", "{0:N2}") %>'
Visible='<%# ShowLabel %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
The code behind it:
protected void MasterDisplay_DataBound(object sender, EventArgs e)
{
DataSourceSelectArguments sr = new DataSourceSelectArguments();
DataView dv = (DataView)CheckForCommit.Select(sr);
if (dv.Count != 0)
CommittedOrNot.Text = dv[0][0].ToString();
//for displaying where data is pulled from
}
public bool ShowBox
{
get
{
return (CommittedOrNot.Text == "This has not yet been committed.");
}
private set { }
}
public bool ShowLabel
{
get { return (CommittedOrNot.Text != "This has not yet been committed."); }
private set { }
}
Any ideas what's causing this disconnect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我只需要在 Commit_Click 中添加 UpdateRows 和 DataBind
Turns out I just needed to add UpdateRows and a DataBind in Commit_Click