Your question is confusing. If you're having trouble writing the code
for a repeater I suggest going to
www.4guysfromrolla.com. They have a
most excellent article on the subject. Also highly recommend this book:
"ASP.NET Data Web Controls Kick Start." IF the issue is MVC, read on....
This really is not the silver bullet you're looking for. It's going to
take some discussion (from the entire group here!) to get to what you
want.
I assume you mean "MVC" - Model View Controller pattern; not MVP.
Don't confuse the pattern with the implementation.
MVP is a bit different for the web. BTW get this most excellent book
and you will understand patterns. "Head First Design Patterns" by Eric
Freeman & Elisabeth Freeman (OReilly press). this book has a section
on MVC and MVC for web in particular.
We are doing a 3 tier approach for our web application but we are not
implementing MVC per se. I'll tell you what we're doing and maybe that
will help. In particular I used a DataList so I think it's similar to
your problem.
The first tier is the web interface. It has a Datalist and we have
home-made header and footer web controls as standard things on all our
pages. The code-behind simply gets the data on postback, I wrote code
to loop through the DataList just as your code shows, and bundles it
up in a meaningful way. In my case I have an ArrayList of
"activityDescription" objects. Then code-behind for this page
instantiates a "business object" - the second tier and passes the
ArrayList to the business object.
The business layer does our data validation, calling the validation
methods for each item in the ArrayList and building up a string of
error messages. Also this Business object in turn instantiates a "data
layer" object and passes this data to this 3rd tier. The 3rd tier
iterates through the ArrayList, getting the data and storing it to the
database.
Additionally I have a "ActivityDescription" class which of course
"holds one record's worth" of data, and has data validation functions
in it.
So I have the following files:
PS3320.aspx - the UI
PS3320.aspx.cs - Essentially this is the code you are showing us here.
The business object:
PS3320.cs - Holds an arraylist of ActivityDescription objects. runs
validation functions. Passes arraylist to data layer.
The Data Layer
ourDAL.cs (ie. "DAL" = Data Access Layer) - Iterates thru the
arraylist, get's the data and stores it to db. Also fetches data from
DB and bundles it into an arraylist.
The Data Structure
ActivityDescription.cs - Has basic data and all the data valiation functions.
There is nothing magic about interfacing the layers. Sometimes one gets
the impression from reading about patterns that very general interfaces
can throw around data w/o knowing it's specific structure, types, etc.
and like magic it shows up, but fundamentally each layer must
understand what data is being passed; so each field is displayed in the
proper place on the screen, so that the proper data validation checks
are done, and so it's saved in the proper place in the database.
Therefore each tier "knows" the ActivityDescription class so each layer
can "bundle" and "unbundle" the data as needed. Thus *every layer*
knows it's getting an ArrayList of ActivityDescription objects. It's
the "ArrayList part that is "generic." Once passed the other layer must
know about the data in the ArrayList.
And Now On To MVC
"Head Start Design Patterns" says that the adaptation of MVC to the web
is called "Model 2". Note this book uses Java and Java Terms, so I'm
translating as best I understand it. So in summary:
** You make an HTTP request which is received by [the code behind]
** The [code behind] acts as the controller. It will make the request
for data from the database. The book says "the result ... is usually
bundled up in the form of a JavaBean." I would say this is the
functional equivalent of my Arraylist of "ActivityDescription" objects.
** The controller forwards control to the view. The view is what you
see in Visual Studio in the "design" and "HTML" screens. The Repeaters
DataBind() takes care of getting data to the view /screen.
** the view returns a page to the browser via HTTP.
Is My Application using MVC then?
I'd say not in the strict academic sense. MVC is a composite of
"strategy", "observer", and "composite" patterns. We did not
consciously design these composite patterns. But the .NET paradigm of
separation of HTML from code-behind blurs things. So perhaps you could
say .NET partially implements MVC already. I'm not so sure our design
decouples the parts like strict adherience to MVC would. But this would
perhaps just be an academic exercise for us. Because in the final
analysis using patterns, for patterns sake alone, is not a good idea.
Patterns should help create good design; design should not necessarily
evolve into defined patterns. They are "patterns" after all, not
hard-and-fast rules.
On 2006-11-05 09:40:02 -0600, Bill44077
<Bi*******@discussions.microsoft.comsaid:
Hi,
I am new to the MVP pattern and one of the main reasons that we are
going this route is because we are doing Scrum with 30 day sprints - so
we have a continually morphing design. We are using TDD as well to
improve our ability to refactor... you probably all know this approach.
Although the user iterface is supposedly one of the last things that
you need to do, this is a web app and we have multiple nested Repeaters
on the page. Within these repeaters we have a textbox in one column
that we need to retrieve contents from. I have been struggling trying
to find examples of something like this as I can't figure out how to
expose this to the view through the interface. Having a single control
on the page is easy to use through the interface. Retrieving the data
in the code behind depends on using Repeater names and FindControls,
etc.
The code for that currently looks something like this:
foreach (RepeaterItem pgItem in ProdGroupRepeater.Items)
{
Repeater prodRepeater = (Repeater)pgItem.FindControl("ProductRepeater");
sProdGroup = ((Label)pgItem.FindControl("ProductGroupName")).Te xt;
foreach (RepeaterItem prodItem in prodRepeater.Items)
{
Repeater tierRepeater =
(Repeater)prodItem.FindControl("TiersRepeater");
sProduct = ((Label)prodItem.FindControl("ProductName")).Text;
foreach (RepeaterItem tierItem in tierRepeater.Items)
{
sRecommendedAPY =
((TextBox)tierItem.FindControl("RecommendedAPY")). Text;
sApprovedAPY = ((TextBox)tierItem.FindControl("ApprovedAPY")).Tex t;
sMinBal = ((HiddenField)tierItem.FindControl("MinBal")).Valu e;
RateChangeDTO rcDTO = new RateChangeDTO();
rcDTO.RecommendedAPY = sRecommendedAPY;
rcDTO.ProductGroup = sProdGroup;
rcDTO.ProductName = sProduct;
rcDTO.DistrictID = sDistrictID;
rcDTO.MinBal = sMinBal;
ListOAPYs.Add(rcDTO);
}
}
Is there some way to retrieve the data from these textboxes in the MVP
pattern? I searched for a couple days and coudn't find any examples
similar enough that I could apply.
If this isn't enough info to help, I could put together a simple
example that uses these same concepts. Maybe I'm totally off base here
- like I said, I'm completely new to all of this.
thanks!!
Bill