VS 2010 - Casting SiteMapNodeCollection To IEnumerable
Feb 19, 2013
Why it's not possible to cast a SiteMapNodeCollection (eg. SiteMap.CurrentNode.ChildNodes) to an IEnumerable<SiteMapNode>? I was wanting to do some filtering of the collection via LINQ, but this might not be possible?
The MSDN page says it implements IList, ICollection, and IEnumerable, so I don't see what the problem is.
View 4 Replies
Similar Messages:
Apr 16, 2012
I'm using a third party control called an Accordion from Juice UI. Within that control, I have a table with labels.
VB.NET Code:
<juice:Accordion ID="accSwrlHddRepl" runat="server">Â
<juice:AccordionPanel runat="server" Title="HDD Information">Â
<PanelContent>Â <p>Â <table style="width: 99%;">
<tr>Â <td class="style2">
<asp:Label ID="Label2111111" runat="server" Text="Original HDD:"></asp:Label>Â Â
[Code] ....
I can't access the label directly, so I'm trying to use the FindControl method to get it and set it's text property.
VB.NET Code:
CType(Me.accSwrlHddRepl.FindControl("lblFirstHddReplacement"), System.Web.UI.WebControls.Label).Text = "string"
But I get a NullReferenceException. So I moved the label outside of the table and put it just inside the accordion. The same behavior occurs. Then I gave the accordion panel an ID and did FindControl there, but the same issue occurs.
View 9 Replies
May 20, 2010
Whats the best method of casting. I've been using syntax like this:
Button btnSubmit = (Button)item.FindControl("Btn_Submit")
but is this better or just different:
Button btnSubmit = item.FindControl("Btn_Submit") as Button
View 3 Replies
Feb 17, 2011
I'm using linq to sql to populate a list of objects. One of the fields I'm interested in is stored as a tinyint. How should I declare this property type in my object definition? As a Short? Byte? Int16?
View 4 Replies
Nov 7, 2010
I have this problem where I am passing NVARCHAR parameter to a stored procedure, and the field type in the table for that parameter is INT.
I am doing that because I am using IN function, and for example if I want to send multiple parameters, that is the only possible way to do through .NET. Or not? The SP doesn't get executed because of the wrong type, and I am trying to cast the value, but I get an error. Here is how I am trying:
Example:
@Parameter nvarchar OrderStatusID = ('30, 40')
(o.OrderStatusID IN (CAST(@OrderStatusID as int)) OR @OrderStatusID IS NULL)
Is there a way to cast each value separately, or what will be the best way to cast whole value as INT.
View 2 Replies
Jun 16, 2010
I am pulling a 'long' value from Session, using a generic property, and it is crashing. so I have:
public static T Get<T>(string key)
{
if(...)
return (T)System.Web.HttpContext.Current.Session[key];
...
}
When debugging, the value is 4, and it crashes.
View 3 Replies
Apr 21, 2010
i have a xml file and i am retrieving its value using Linq to xml and assigning it to ViewData.
[code]...
but foreach (var item in ViewData["Persons"] is giving type casting error..what should be the exact type csting so that i can retrive values in the format item.Fname.
View 3 Replies
Mar 29, 2010
I'm calling a method like this:
DataTable dtModifiedData = detailsGrid.GenerateRowColumnDataTable(Request.Form)
The GenerateRowColumnDataTable method retrieves all form variables with <input> tags. My problem is that my columns are named in a strange format like this:
#X#_G1_NAME_1 so when I look at what's being rendered I see %23X%23_G1_NAME_1 so I thought I could use Server.URLEncode() around Request.Form but I'm getting an errot that it can't be converted to a string. What would you do in this case?
View 7 Replies
Jul 28, 2010
I have a bit column that is saved as 1 or 0 in the database. I want to check the value in the table and then do an if statement depending if its 1 or 0. How can I convert it to an int?
i had
lockValue = (int)sqlCommand1.ExecuteScalar();
I want to assign it to the lockValue int variable. I then want to go on and check
if (lockValue == 1) {
// stuff
}
View 1 Replies
Sep 23, 2010
I have a situation where I'm iterating through all the controls on a form, specifically looking out for any of these three types of controls: Labels, TextBoxes, CheckBoxes
I can, of course, get the type of the control and then use a Switch-Case construct to cast labels as Labels, textboxes as TextBoxes, and checkboxes as CheckBoxes.
But I'm wondering if there's a way to do something with one or two lines of code to gain access to the Text property of each of these controls?
View 4 Replies
Nov 10, 2010
I am passed an IQueryable that might be already be ordered and that therefore might be an OrderedQueryable. I need to apply it a new ordering via reflection, anb before choosing if calling either OrderBy or ThenBy I need to now if the Queryable is IOrderedQueryable.
Now comes the problem! To see if may variable say query is an IOrderedQueryable I do:
IOrderedQueryable orderedQuery = query as IOrderedQueryable;
One might expect orderedQuery be null in case query is not an IOrderedQueryable ! INSTEAD orderedQuery is NEVER NULL. It takes the value of a different type!
I understand that this might happen because of deferred execution...
I tried also: query is IOrderedQueryable and it is always true!
How can I verify if query is actually an IOrderedQueryable before getting an exception when calling ThenBy?
The IQueryable comes from the Entity Framework 4.0
I am able to see it if I access the object that is behind the interface, but this way I would loose the benefif of using interface, and my class might not work with a different implementation of the IQueryable.
View 2 Replies
Oct 15, 2010
Im dynamically generating an HTML Select Box, lets call it myselect. Im creating this select box based on some database values Im generating an HTML Select Box.. almost like a string that Im just spitting out to the page. So it's never a control in the codebehind, just part of a string thats rendered as HTML by the browser. If I submit my form, and in my codebehind I perform:
Dim myVal as String = Request.Form("myselect")
That code will give me the VALUE of the myselect select box. How can I refer to this control to cast it as a System.Web.UI.HtmlControls.HtmlSelect control? Request.Form seems to give me the value, but I want to reference the object itself..
View 3 Replies
Oct 15, 2010
I'm using the default SqlMembershipProvider,but I've created a custom MembershipUser class (SoeMembershipUser) because I needed a "DisplayName" property.All the DisplayName does is look at the UserName and format it differently.When I try to cast a MembershipUser to a SoeMembershipUser user I get an InvalidCastException.
Exact error is:
"Unable to cast object of type 'System.Web.Security.MembershipUser' to type 'Soe.Tracker.SoeMembershipUser'."
Here is the code that fails:
SoeMembershipUser user = (SoeMembershipUser)Membership.GetUser(username); // invalid cast
I have also tried casting later like so:
MembershipUser user = Membershipship.GetUser(username); // ok
...
string displayName = ((SoeMembershipUser)user).DisplayName; // invalid cast
Here is the SoeMembershipUser class:
NOTE: I left off the constructors at first, but added them in later when I started having problems. Adding them made no difference.
public class SoeMembershipUser : MembershipUser
{
public SoeMembershipUser()
: base()
[code]...
View 2 Replies
Jul 19, 2010
I´m trying to use session to store a value (id). The problem is that I have to store it as a string. When trying to use the instance of the id I get the error:
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 156:
Line 157: Nemanet_Navigation newFile = new Nemanet_Navigation();
Line 158: newFile.Nav_pID = (Guid)Session["id"];
Line 159:
Line 160:
This is where I get the id and that seems to work fine. Session["id"] gets the value.
[code].....
View 3 Replies
Jun 9, 2010
i was looking at one example on msdn [URL], but i can't really understand it.
View 1 Replies
Mar 14, 2010
refer me few article which describe the basic use of IEnumerator and IEnumerable,
View 3 Replies
Mar 6, 2011
I have function it will return IEnumerable as.
IEM = myclass.getdata("name");
How to read the data in IEM as it consists of many columns. I have to display the values into labels and textboxes.
View 3 Replies
Jun 2, 2010
I want to enable/disable controls of a asp.net page against a logged in user's permission. say 'admin' & 'hr' can change user's birth date text-box in a page but others will see the text-box as disabled.
so i wrote a function like this
[code]....
View 3 Replies
Mar 9, 2011
i try casting the gridview datasource to datatable using the following code but the datatable always nothing.
Dim DT As New DataTable
DT = DirectCast(gv.DataSource, DataTable)
the gridview is bound using dataset at code behind without using sqldatasource.
i m trying to filter the gridview without geting the data from database, is there is another way to do this?
View 4 Replies
May 18, 2010
I am trying to save the every date clicked in a List of Date using a session variable. I am getting a casting error ..."when casting a number the number must be less than infinity".
[Code]....
View 1 Replies
May 1, 2010
I am using LINQ for data connectivity and have made class which return me the result set into presentation here is the syntax:-
public List<ClsDermaInvestigation> MthdisplayInvestigation()
{
List<ClsDermaInvestigation> lstinvst = new List<ClsDermaInvestigation>();
ISingleResult<USP_Patient_Dermatology_InvestigationResult> investresult = objderma.USP_Patient_Dermatology_Investigation(PatientID, RepDate, Hb, TLC, F);
foreach(USP_Patient_Dermatology_InvestigationResult rel in investresult)
{
ClsDermaInvestigation objinvest = new ClsDermaInvestigation();
objinvest.Albumin = Convert.ToDouble(rel.Albumin);
objinvest.ALP = rel.ALP;
objinvest.ANA = rel.ANA;
objinvest.Date = rel.date;
lstinvest.add(objinvest)}return lstinvest}
This list is returning me the result.It works fine but in 1 case am using the same list to bind my Date dropdownlist.
//aspx.cs code
List<Dermatology.ClsDermaInvestigation> objlstinvest = objinvest.MthdisplayInvestigation();
//Array s = objlstinvest.to
drpDate.DataSource = s;
drpDate.DataTextField = "Repdate";
drpDate.DataValueField = "Repdate";
drpDate.DataBind();
But it throws an error that list does not conatin a property with "Repdate";. How can i bind this list with dropdownlist?? Can i convert it into some type so that i would be able to bind it??
View 2 Replies
Apr 1, 2011
table1 row = _db.table1.FirstOrDefault(r => r.ReferenceID == refNumber);
Is there anyway to cast row to IEnumerable?
((IEnumerable<table1>)row) - does not work
View 1 Replies
Apr 19, 2010
I'm trying to update values I have stored in an IEnumerable using UpdateModel, but it isn't reflecting the changes when I step over it in Debug.I also tried upating it using a foreach loop and updating the values in each object T within the IEnumerable<T>. The values are changed at the object level, but it seems that the value of the object in the IEnumerable isn't being changed.I was looking at IEnumerable<T> and didn't see a way to update it... I'm thinking that I might have to assign the updates to some other data structure, then convert it to an IEnumerable or something before I try to save my repository
View 6 Replies
May 18, 2010
I've read some articles about this but for some reason they're just not doing it for me. I'd like to understand the difference between
IEnumerable<string> myList and List<string>myListToo
View 7 Replies
Jun 29, 2010
I have IEnumerable object with value1 and value2. value2 is an array and value1 is string. I want to databind this object to Listview like that. So both value1 and value2[0] (always first item in array) could be accessed via <%# Eval("value1") %> and <%# Eval("value2") %> .
How to write expression to handle both items ?
ListViewItems.DataSource = f.Items.Select(t => t.value1, t.value2[0]);
ListViewItems.DataBind();
View 1 Replies