conditional readonly textbox in a datagrid

G

Guest

I am having a hard time with this one, and I thought it would be easy.

I have a datagrid in which I have textboxs for users to enter data. One of
the fields in the database behind the datagrid tells me if the textbox is
readonly or not. I am having a hard time setting the readonly property of the
textbox with a conditional if statement (IIF).

Here is the coding;
<asp:TemplateColumn HeaderText="Data Entry">
<ItemTemplate>
<img src="images/Barrow.gif" onclick="CopyTotal(this);" title="Click here to
copy Previous Field to this text box">
<asp:TextBox CssClass="printableTextbox" runat="server"
onchange="AddRequesterName(this);" Readonly='<% #
iif(Container.DataItem("NotAllowed")=1,True,False) %>' id="txtDataEntry"
Text='<% # Format(Container.DataItem("Data"),"$#,##0.00") %>'
onblur="this.value=FormatCurrency(this.value,1);">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>

What am I doing wrong with the readonly? If I look at the source, it isn't
being produced within the page.

Thank you,
Lyners
 
G

Guest

probably the IIF statement always returns false... you may want to give it a
try changing it to a function similar to below.. this will help debugging the
condition..

<asp:TextBox ReadOnly='<%#CheckReadOnly(DataBinder.Eval(Container.DataItem,
"NotAllowed").ToString())%>' ID="Text1" ></asp:TextBox>

in code behind ..
protected bool CheckReadOnly(string val)
{
if(val == "1")
return(true);
else
return(false);

}
 
G

Guest

Yes, I just had to step through it to see what the data was sending back. i
had the field defined as bit, and because so it was already true or false. I
just needed to read the field... no iif, or anything else.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top