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?
Turns out I just needed to add UpdateRows and a DataBind in Commit_Click