Generics - Declarative Syntax For A Collection Of Value Types?

Jul 16, 2010

I know that in ASP.NET (talking about 2.0 here primarily) one can set a property on an object that takes a collection of things (an enumerable type I'm guessing is the trigger) and then reference it declaritivly. For example:

<ObjectDataSource properties="blahblahblah">
<SelectParameters>
<asp:Parameter />
</SelectParameters>
</ObjectDataSource>

It is the <asp:Parameter /> part which is the root of my question. Say I wanted a simpler collection on a type. Say a List<String> or if generics are out, an IntegerCollection or StringCollection. How would I use that declaratively? Is <string value=''> allowed, or can I put raw values into it like <StringCollection>string, string, string</StringCollection> or what?

EDIT:

I feel like I was not clear enough in my question. I understand that ObjectDataSource implements its SelectParameters property as a ParametersCollection, and that one can use that property declaratively (in an ASPX page) to set up Parameter types within that collection. What I'm wondering is if I made something like StringCollection as a property on another control, is there a syntax (in ASPX) for adding strings to that collection? Or would I have to define a wrapping class like how DropDownList takes ListItems to fill its collection?

View 2 Replies


Similar Messages:

Restrict The Generics To Take Only Value Types?

Jul 12, 2010

I had asked with one question in the interview regarding generics

How can we restricts the one generic method to take only the value types.It should not be able to take reference types.

View 2 Replies

Mvc Views With CLR Generics Syntax In Inherits Attribute?

Oct 18, 2010

For reasons I won't go into I need to use CLR generics syntax in an ASP.NET MVC view.

I.E. NOT this:

System.Web.Mvc.ViewUserControl<someobject>

but this:

System.Web.Mvc.ViewUserControl`1[[someobject]]

When I run the application I get

Parser Error: could not load type `System.Web.Mvc.ViewUserControl`1[[someobject]]

View 2 Replies

Databinding To A Sub Object Declarative Syntax?

Mar 9, 2010

What is the format for databinding to a complex "object"? I have a linq to sql class that has containment, i.e object.containedobject.I want to reference the sub objects fields declarative.So I've tried my MySubField.MyBasicProperty and that did not work, as well as, MySubField_MyBasicProperty.

View 2 Replies

C# - How To Bind "OnDataBound" Event Of "DropDownList" In Declarative Syntax To A Static Method In Some Other Class

Jun 16, 2010

How to bind "OnDataBound" event of "DropDownList" in declarative syntax to a static method in some other class ?e.g<asp:DropDownList runat="server" id="d1" OnDataBound="SomeOtherClassThanThisPage.StaticMethod"></asp:DropDownList>

This will give the error, "Page does not contain a definition for SomeOtherClassThanThisPage. it like this or it be done in the Code Behind only ?

View 2 Replies

Architecture :: Class Design - Application Allows Admins To Add Types Such As Document Types?

Oct 12, 2010

I have an application that allows admins to add types such as document types and training types that are in seperate tables with a foreign key in a transaction table.

When structuring my class I decided to go with an abstract-like pattern (without the factory methods though). So I have a Type abstract class that defines my Save, Delete, and GetList methods. I have a training type class that inherits this class. The thing is all types have 3 main properties - defined in the abstract base - but have different source tables and thus different store procedures in my DbCommand object. So basically I repeat setting up the same parameters on all the derived classes. I would like to implement the common stuff in the base but I am getting thrown off by the difference in data sources.

View 2 Replies

How To Get Value Of Property By Name Through Generics Of A Class

May 11, 2010

I have a class, let's say class Sample. Sample has unknown properties but inherits an interface ISample. Said interface includes one method which I'm trying to create. This interface has a method called getPropertyValue(object o, string PropertyName).

It returns the value of the o.PropertyName using generics (unless you have a better suggestion). How do I write it? In other words, I want to be able to pass the name (as a string) of a property and return its value. Samples in C# preferrable but VB ok and any comments or suggestions are welcome.

View 2 Replies

Understand Polymorphism When Using Generics In C#?

Aug 25, 2010

I am having a problem understanding how polymorphism works when using generics. As an example, I have defined the following program:

public interface IMyInterface
{
void MyMethod();
}.....

So, at least I haven't completely misunderstood that. I am unsure exactly how I am to write a method that accepts a generic collection of classes that conform to the same interface.

I have a plan to completely hack around this problem if need be, but I would really prefer to do it properly.

View 3 Replies

C# - Reflection And Generics Get Value Of Property?

Apr 29, 2010

i am trying to implement a generic method which allows to output csv file

public static void WriteToCsv<T>(List<T> list) where T : new()
{
const string attachment = "attachment; filename=PersonList.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();

[Code]....

but I am not able to get the value of the object's property

View 2 Replies

Generics And Duck-Typing XML In .NET?

Feb 12, 2010

I'm working with some XML representations of data instances. I'm deserializing the objects using .NET serialization but something in my soul is disturbed by having to write classes to represent the XML... Below is what I'd LOVE to do but I don't know if the syntax or if it is even possible:Consider the following:

dim xmlObject = SomeXMLFunction() 'where some function returns an object/string representation of xml...
xmlObject.SomePropertyDefinedInTheXML = SomeFunction()

View 4 Replies

Finding Types Of Websites And Types Of Categories

Mar 1, 2011

i Dont know how many types of asp.net websites.

ie. asp.net webiste types of categories.

Give me the deatiled Information.

View 1 Replies

Find # Of Occurrences & Count In String Using Collections / Generics?

Mar 4, 2010

I tried so much working with this to get distinct Words and their count. I'm using ASP.NET 2.0. And i also googled so much.

1)Ex(String): The DOTNET is Very Cool! The Best.

2) Capture all the sequences like Space, FullStop, Question Mark, Exclamation, Apostrophe, New Line....(May be with RegEx?)

3)Split Words According to the above sequences

4)Get Distinct Words(Occurences) and their count based on the input string in 1st statement.

Desired O/P:
The - 2
DOTNET - 1
Is - 1
Very - 1
Cool - 1
Best - 1

This is my Sample Code for your Ref.

[Code]....

View 3 Replies

Is It Possible To Declarative Pass Properties

Apr 19, 2010

is it possible to declarative pass properties (in my case property of DataContext type) to User Control without DataBinding.

Now code looks like this:

[code].....

View 4 Replies

Forms Data Controls :: Bind A Collection Within A Collection To A Gridview?

Jul 26, 2010

I have a list of objects that I want to bind to a gridview. Creating that list and binding it works fine for most of the public properties in that list.

There are some objects contained in each of those objects... for instance there is an Address object.

object.Address.Line1;

object.Address.Line2;

When I bind this to my gridview, I have no issues with stuff like object.DateRegistered, but how can I access things like object.Address.WhatEverProperty? I always get this error:

"A field or property with the name 'xxx.xxxx' was not found on the selected data source."

View 7 Replies

Access :: Syntax Error (missing Operator) In Query Expression / Get Conflict With CommandText Syntax

Aug 8, 2010

I'm having problem in inserting text from a textbox in which user write or copy some text which may contain special characters ( " , . ) etc. If there is any special character it get conflict with CommandText Syntax and generates error in inserting. I want to insert all these characters. How could i do it?

Code:

[code]....

View 1 Replies

Why Can't Use C# Syntax In Inherits Attribute For A Closed Generic But CLR Syntax Is Fine

Jan 15, 2011

The following CLR syntax works fine in my aspx page:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Website.MyBasePage`1[HomePageViewModel]" %>

But this C# syntax does not:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Website.MyBasePage<HomePageViewModel>" %>

Note, I am not using ASP.NET MVC, but this works fine if using System.Web.Mvc.ViewPage<> from ASP.NET MVC.
My MyBasePage looks like this:

public class MyBasePage<TModel> : Page where TModel : class {
public TModel Model
{
get { return (TModel)HttpContext.Current.Items["model"]; }
}
}

View 1 Replies

Web Forms :: User Control With Declarative Paramaters?

May 19, 2010

Is there anyway to pass parameters to a custom user control using declarative paramters.E.g.

<MyUserContrl id = "" runat="">
<PARAM Title = ""/>
<PARAM SelectTable="" />

[code]...

View 6 Replies

C# - Interdependent Dropdowns In Gridview Using Declarative Programming?

Feb 14, 2010

I have a binded dropdown control in the gridview under edittemplate. Now i wanted to populate the second dropdown in the same gridview based on the first selection. I dont have options but use the gridview & declarative coding.

Also i am using the objectdatasource here.

View 1 Replies

MVC :: Razor: Referencing Declarative Html Helpers?

Dec 15, 2010

I'm trying to write a simple declarative html helper: [Code]....

The helper works fine if I embed it into the page I want to use it on. But if I move it to a separate .cshtml file and place that file in the ~/Views/Helpers directory, my view can't be compiled anymore because the helper is not found.According to Scott Gu's blog article on Razor it should work.

The only workaround I have found so far is placing the Html helper in App_Code and Referencing it as @[MYHTMLHELPERFILENAME].Echo(...) . This works but is a bit messy since I don't want to repeat the name of my extension method (Echo.Echo("inputstring"), nor do I want to put all of my html helpers into one single file (something like MyHtmlHelpers.cshtml).It certainly isn't what Scott announced either, so I guess I must be doing something wrong.

View 4 Replies

MVC :: 3 RC2 - Convert ASPX Syntax To Razor Syntax For Asp:Hyperlink?

Dec 15, 2010

For reporting we used report RDLCs and displayed using an ASPX form. We implemented using the route as shown below. This resulted in forcing us to use the page route below and also to use the hyperlink instead of the normal Action Link. The question is how do we convert the asp:hyperlink ASPX syntax to Razor syntax.

//Custom route for reports routes.MapPageRoute( "ReportRoute", // Route name "Reports/{reportname}", // URL "~/Reports/{reportname}.aspx" // File );
<li><asp:HyperLink ID="hypReport" runat="server" NavigateUrl="<%&#36;RouteUrl:routename=ReportRoute,reportname=StaffRpt%>">Staff Report</asp:HyperLink></li>

View 2 Replies

Web Forms :: How To Use Collection Class For Collection Of Data

Mar 31, 2010

I want to know that how i use the collection class for storing some data and save it letter in the data base.

View 4 Replies

MVC.NET Tag For Checking Roles (equivalent Of Declarative Attribute PrincipalPermission)?

Apr 5, 2010

I use declarative roles in my MVC.NET controllers and I have a custom membership & roles provider.This works fine:

[Authorize(Roles = "ADMIN")]

Also, I have a base MVC.NET CustomController class that all controllers derive from, and it has a "currentUser" property that is auto-fetched from the session on demand, so all controller code just refers to "currentUser" and doesn't worry about sessions, httpcontext, etc. I've implemented the membership provider properly, as it works with other parts of the framework that just deals with providers, but until now I had not tried to access the "User" principal from a view.What is the simplest syntax for check roles in a view page? I know I can use a helper to generate a partial view but I don't want that here, I want to explicitly wrap some sections of a page in some role checks.Something like this:

<% if(currentUser.IsInRole("ADMIN") { %>
...
<% } %>

View 1 Replies

Web Forms :: How To Add Multiple Controls To Declarative Catalog Part By Default

Feb 11, 2011

i want to add control 1, control 2 etc.. by default in Declarative Catalog Part

and using following code

[Code]....

but it only displays last item in it

any one guide me what mistake am i doing or what is the solution to my problem?

actually i want to give default 4-5 webparts options so that user could add it to page

View 1 Replies

Forms Data Controls :: Exception Handling With Declarative GridView?

Jan 17, 2011

I'm using Visual Web Developer 2010 Express with C# 2008 and .NET v4.0 to create a website which will have a database application. The database is SQL Server 2008.

I would have searched this forum for similar questions but I can't find a 'Search this forum' option! So I apologise if someone has already answered this.

I've successfully displayed rows from my database by dragging and dropping a GridView and an SQLDataSource control onto my page, and by using the Connection Wizard to set them up. But when I go live with my new pages, I will have to put my database in a different folder, and until I edit the web.config connection string to point at it I expect to get an exception.

I understand that when you try and open a database connection, this is the perfect place to use try...catch exception handling. But all the examples I can find put the try-catch code on the Button_Click event! Where should I put it? I can' t find anywhere where my controls actually attempt to open the database!

I know I could rip out what I've done and write all the code to connect to the database myself, but as I've finally got everything to work I would prefer to make the change as small as possible. So, what is the minimum change I have to make to add exception handling to my datasource/ gridview?

View 6 Replies

Add Controls To A Collection And Update From Collection?

Mar 25, 2011

I have an ASP.NET app with lots of textboxes all over the page that need updating at various points through program execution.

These textboxes actually belong to a certain class, so for easy updating I thought I could create a Dictionary(Of string, object) and add the control.ID and the control to it and then for updating do something like this:

(in case of updating textbox.text):

[code]....

However the text property of the textbox does not actually get updated. I'm mainly trying to avoid having to manually do textbox.text = somestring for each one of my textboxes every time I have to update them.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved