C# - Multiple Selection In ForEach Extension Method?
Jul 20, 2010
Is it possible to select multiple entiies in ForEach Extension Method?
(i.e)
partial code is given
DataTableA.AsEnumerable().ToList().
ForEach(x=>
{
x.SetField<string>("Name","Jon Skeet"),
x.SetField<string>("msg","welcome")
});
when i apply multiple selection in ForEach
x=>
{
x.SetField<string>("Name","Jon Skeet"),
x.SetField<string>("msg","welcome")
}
I am unable to complete the statement.
View 1 Replies
Similar Messages:
Feb 12, 2010
i saw the extension method code but i could not understand what it is and what is the utilities of extension method.
View 3 Replies
Mar 12, 2011
I am using Tuple class in WCF Service. When i add reference to my web project I get Tuple class. Now i want to add an extension method to Tuple<> class in my service which will be accessible in my Web project.
View 1 Replies
Feb 22, 2010
I want to ask, does adding extension methods to datatypes works in the same way as Microsoft's methods or do they have any limitaion.
This is relevant to experienced programmers who had find some limitations while using them.
View 3 Replies
Mar 9, 2010
I recently found out about C# extension methods and wrote this one:
/// <summary>
/// Short-hand for setting the data source and binding it.
/// </summary>
/// <param name="me">The control to set and bind the data source of.</param>
/// <param name="dataSource">The data source.</param>
public static void BindTo(this DataBoundControl me, IEnumerable dataSource)
{
me.DataSource = dataSource;
me.DataBind();
}
What do you guys think? Is this a reasonable extension method to use in a professional ASP.NET project?
View 4 Replies
Sep 5, 2010
I have the following Extension Method
Imports System.Runtime.CompilerServices
Namespace Extensions
Public Module IntegerExtensions
<Extension()>
Public Function ToCommaDeliminatedNumber(ByVal int As Integer) As String
Dim _input As String = int.ToString
Select Case int
Case Is > 99999 : Return _input.Remove(_input.Length - 3) & "k"
Case Is > 9999 : Return Math.Round(Double.Parse(int / 1000), 1).ToString & "k"
Case Is > 999 : Return String.Format("{0:N0}", int)
Case Else : Return _input
End Select
End Function
End Module
End Namespace
And in one of my classes I'm using user.Reputation.ToCommaDeliminatedNumber I am importing the Extensions Namespace into the Class, but the error I'm getting is...'ToCommaDeliminatedNumber' is not a member of 'Integer?'. I do have other Extension Methods for Strings and Dates that work exactly as expected... I'm just at a loss on this one.
View 1 Replies
Oct 8, 2010
I know there is a ListBoxFor extension method among the ASP.NET MVC Html helper extension methods, but I always thought that a checkbox list is more user-friendly than a list box.
There was a very convenient CheckBoxList control in good old WebForms, but obviously that is out of the picture now. The question is, why is there no way in ASP.NET MVC to create a check box list? How can I write my own extension method that creates a check box list and behaves in a similar way ListBoxFor behaves?
View 3 Replies
Dec 21, 2010
I am stuck with the database row level security model that my predecessor has implemented on this project. I am trying to make an extension method for my linq to sql classes to make it easier to filter rows of data in my linq queries. The problem I am facing is that I need to somehow tell it how to access the primary key value of the object in the where clause. I get errors about DynamicInvoke(object[]) cant be converted to SQL. Here is a sample of what I am working with:
[Code]....
How do I do this?
View 1 Replies
Jul 9, 2010
VWD 2008 Express. Visual Basic.
I am using the Directory.GetFiles method as follows:
[Code]....
As expected, it returns files with the ".pdf" extension. I would like to be able to specify more than one extension (like "*.doc*" and "*.txt*", etc.). How can I use GetFiles to return files with more than one desired extension, without returning all files?
View 2 Replies
Jan 18, 2011
I'm binding an object to a gridview. The object (LeClient) consists of several variables, two of which are related to its phone number. One variable contains a string of digits (LePhone) and the other contains an int that represents the country code (LeCountryCode). I have an extension method for strings that works to format the string LePhone and that I'd like to pass it LeCountryCode as the parameter.
So far, on RowDataBound I have an event handler with the following line:
e.Row.Cells[5].Text = (string)(e.Row.Cells[5].Text).ToPhoneFormat(1);
I'd like to replace the 1 with the corresponding country code that's stored in the object LeClient associated with the row. How does this work? I tried
.ToPhoneFormat(e.Row.DataItem("LeCountryCode"));
View 1 Replies
Jan 18, 2011
I would like to know what the pros and cons are of creating an extension method v a partial view. From my understanding, htmlHelper extension methods are better as they enable one to unit test the view.
e.g. Assert.AreEqual(Html.Price(), "<td><tr><td>Price</td><td>4.50</td></tr>");
where the Price() method contains the presentation logic.
Since both the extension method and partial view are reusable, what then is the point / benefit of a partial view?
View 7 Replies
Mar 23, 2010
I have an extension method which I can use from the .cs codebehind of an aspx page, but if I try to do it in a code block in the aspx, it can't find the extension method. Is there something I need to add to the page?
View 2 Replies
Oct 24, 2010
Inside my repeater I'm calling an extension method like so:
[Code]....
he above is giving me an "Object not set to an instance of a object" exception inside the extension method. If I comment the above expression out, it works fine, and the items are binded wtih no problems.
View 1 Replies
Sep 28, 2010
I am trying to extend controller with extension method which redirects to 404 page.
[Code]....
However, controller.View() method is internal and can't be called outside class methods.
View 3 Replies
Jul 22, 2013
I am using MultiView and View in .NET but i am getting this error: Compiler Error Message: CS1061: 'ASP.default_aspx' does not contain a definition for 'NextView' and no extension method 'NextView' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)Source Error:
Line 24: THIS IS VIEW 1 . HAVE A LOOK ! iTS COOL BECAUSE OF C#.<br />
Line 25: <br />
Line 26: <asp:Button ID="Button1" runat="server" Text="nEXT" OnClick="NextView" /> Line 27: <br />
Line 28: <br />
Source File: c:UsersxxxxDocumentsVisual Studio 2012ProjectsWindowsAzure2TestCRoleDefault.aspx Line: 26
This is my aspx.cs code: using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System. Web.UI. WebControls;
namespace TestCRole{ public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { MultiView1.ActiveViewIndex = 0; } } void NextView(object sender, EventArgs e) { MultiView1.ActiveViewIndex += 1; } void PreView(object sender, EventArgs e) { MultiView1.ActiveViewIndex += 1; } protected void MultiView1_ActiveViewChanged(object sender, EventArgs e) {
} }}
And this is my aspx file:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <p> <br /> <asp:MultiView ID="MultiView1" runat="server" OnActiveViewChanged="MultiView1_ActiveViewChanged"> <asp:View ID="View1" runat="server"> THIS IS VIEW 1 . HAVE A LOOK ! iTS COOL BECAUSE OF C#.<br /> <br /> <asp:Button ID="Button1" runat="server" Text="nEXT" OnClick="NextView" /> <br /> <br /> </asp:View> <asp:View ID="View2"
[code]...
View 1 Replies
Apr 6, 2010
i need to find, string or boolean from database..
that is, i have a table i need to check that is string or boolean? to assigne other vairable?
using some extensions methods?
View 3 Replies
Mar 16, 2011
I am using the cascading dropdownlist controls from the Ajax toolkit. I have everything working perfectly and all of my select changes work. I have 3 related select boxes that all work great for single item select. What I need is for my last dropdownlist to allow for the selection of multiple items. I have tried adding the 'multiple' attribute to the final dropdown list and it allows the selection of multiple items but I cannot get the items when I post back, just a single item.
View 7 Replies
Aug 7, 2010
I want to iterate through HtmlTable (Server Side) in ASP.NET 3.5.
foreach (System.Web.UI.HtmlControls.HtmlTableRow trow in someTable)
{
var x = trow.InnerText;
}
I received an error message that "System.Web.UI.HtmlControls.HtmlTable" does not contain a definition for GetEnumerator.
How to write an extension method or alternative to make HtmlTable as enumerable row collection?
View 2 Replies
Oct 1, 2010
Is something like the below possible?
public static T Sum<T>(this DataTable dt, string columnName)
where T : IEnumerable<decimal>, IComparable<decimal>[code]....
It feels like i'm almost there, but not quite :/
Just trying to sum up either decimal or int values in a column in datatable. Currently getting a compile error, however think this is due to the incorrect generic constraint.
View 3 Replies
Oct 24, 2012
I have a list box that I want to allow the users to select up to 4 items from. I set the selection property to multiple, but for the life of me it won't allow multiple selection. If I pre-select 4 items, they show up as all selected when the page loads, but as soon as I select another, it clears all of them and then only allows one at a time. if I check the source code for the page, the property is set to multiple (see below).
HTML Code:
<td colspan="2" style="height: 28px">
<select size="4" name="MonthsListBox" multiple="multiple" id="MonthsListBox">
<option value="Jan">Jan</option>
<option value="Feb">Feb</option>
<option value="Mar">Mar</option>
<option value="Apr">Apr</option>
<option value="May">May</option>
<option value="June">June</option>
</select></td>
View 4 Replies
Aug 27, 2010
Im trying to test my extension method that converts a list of strings in a string comma separated:
public static class Extensions
{
public static string ToCommaString<T>(this IList<T> input)
{
StringBuilder sb = new StringBuilder();
foreach (T value in input)
{
sb.Append(value);
sb.Append(",");
}
return sb.ToString();
}
public void TestExtension()
{
IList test=new List<string>();
//test.ToCommaString doesnt appear
}
}
The issue is that in the method TestExtension i cant use ToCommaString method. Do you know what's happening?
Could i make available for all my web application this extension method registering in web.config or something similar?
View 1 Replies
Sep 20, 2010
In MVC it's very easy to control routing.
In my classic ASP.NET application I want to "hide" .aspx extension
I can do it with new ASP.NET 4 feature: MapPageRoute
view plaincopy to clipboardprint?
View 4 Replies
May 17, 2010
I have a fileupload feature in my app, there are some files users upload example: varFileName = "myfilename....pdf"
how to remove those multiple dots right before extension.
View 2 Replies
Jan 1, 2010
I know we can set autopostback property of dropdwonlist using javascript or jquery and it will go to action controller specified in Form tag.
[Code]....
but how can we set it to some different action other then what we specified in Form Tag.
View 3 Replies
Jun 8, 2010
i have defined a dropdown list in the controller
[Code]....
then i can show this dropdownlist in my "about" view <%=Html.DropDownList("a") %>.
BUT, now i want to define this dropdown list at my back end. what i want to do is to create a new "Helper".cs file in my project, and create a function within it. so every time if i want to show this dropdown list, i can just simply call this function instead of Add new SelectListItems one by one. is there anyone tell me how to do it?? and is it a good way to create a dropdownlist at the back end?
View 3 Replies