I have a <asp:Repeater> on my web page that is bound to a software-generated dataset.
The purpose of this repeater is to create an index from AZ, which, when clicked, updates the information on the page.
The repeater has a link button like this:
<asp:LinkButton ID="indexLetter" Text='<%#DataBinder.Eval(Container.DataItem,"letter")%>' runat="server" CssClass='<%#DataBinder.Eval(Container.DataItem, "cssclass")%>' Enabled='<%#DataBinder.Eval(Container.DataItem,"enabled")%>'></asp:LinkButton>
The data set is created as follows:
protected DataSet getIndex(String index) { DataSet ds = new DataSet(); ds.Tables.Add("index"); ds.Tables["index"].Columns.Add("letter"); ds.Tables["index"].Columns.Add("cssclass"); ds.Tables["index"].Columns.Add("enabled"); char alphaStart = Char.Parse("A"); char alphaEnd = Char.Parse("Z"); for (char i = alphaStart; i <= alphaEnd; i++) { String cssclass="", enabled="true"; if (index == i.ToString()) { cssclass = "selected"; enabled = "false"; } ds.Tables["index"].Rows.Add(new Object[3] {i.ToString(),cssclass,enabled }); } return ds; }
However, when I launch the page, "The specified cast is not a valid exception" is thrown into Text='<%#DataBinder.Eval(Container.DataItem,"letter")' . I have no idea why, I tried manually casting to String with (String), I tried the ToString () method, I tried everything.
Also, if in the debugger I add a clock for DataBinder.Eval (Container.DataItem, "letter"), the return value is "A", which in my opinion should be good for a text property.
EDIT:
Here is the exception:
System.InvalidCastException is not handled by user code
Message = "The specified cast is invalid." Source = "App_Web_cmu9mtyc"
Stack traces: in ASP.savecondition_aspx .__ DataBinding__control7 (object sender, EventArgs e) in e: \ Documents and Settings \ Fernando \ My Documents \ Visual Studio 2008 \ Projects \ mediTrack \ mediTrack \ saveCondition.aspx: line 45 in System.Web .UI.Control.OnDataBinding (EventArgs e) in System.Web.UI.Control.DataBind (Boolean raiseOnDataBinding) in System.Web.UI.Control.DataBind () in System.Web.UI.Control.DataBindChildren () InnerException:
Any advice would be much appreciated, thanks
EDIT 2: Fixed! The problem was not in the Text or CSS tags, but in the Enabled tag I had to drop it to a boolean value. The problem was that the exception was noted in the Text tag, I donโt know why