I'm not very experienced in ASP.Net, as I work mostly with PHP. I'm trying this, but it doesn't work:
<asp:TextBox runat="server" ID="txtAnswer"
TextMode='<%# IIf(DataBinder.Eval(Container.DataItem, "DoLargeInput"), "MultiLine", "SingleLine" )%>' Text=''></asp:TextBox>
DoLargeInput is a boolean.
Why doesn't this work?
I'm gettin the following error:
System.InvalidCastException: Conversion from string "MultiLine" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
--- End of inner exception stack trace ---
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value)
at ASP.profile_questions_aspx.__DataBinding__control6(Object sender, EventArgs e)
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at profile_questions.LoadObjects()
Any help would be greatly appreciated. Thanks!
From stackoverflow
-
Try:-
IIf(DataBinder.Eval(Container.DataItem, "DoLargeInput"), TextBoxMode.MultiLine, TextBoxMode.SingleLineIt the parse that will convert TextMode="MultiLine" approriately for you. At the point this binding code happens the parseing is over, you need to specify the value as you would in code.
Infinity : Great that works thanks. So TextBoxMode.MultiLine is a global constant?AnthonyWJones : TextBoxMode is an Enumeration type containing the set of valid values for the TextBox controls TextMode property. Its available in the System.Web.UI.WebControls namespace. The value's global name is actually System.Web.UI.WebControls.TextBoxMode.MultiLineInfinity : Thanks for the explanation -
The failed conversion to 'Integer' is because the TextMode property is a .NET
enum, which is represented internally as an integer.TextBoxMode.MultiLineandTextBoxMode.SingleLinerepresent the correct kind of value.On MSDN you can see the
TextBox.TextModeproperty has typeTextBoxMode.
0 comments:
Post a Comment