Showing posts with label strongly-typed. Show all posts
Showing posts with label strongly-typed. Show all posts

Thursday, March 22, 2012

Strongly typed datasets and nested repeaters

I have a strongly typed dataset that returns two tables - "items" and
"itemdetails". In the strongly-typed dataset designer, I've created a link
(relationship) between the two tables based on a foreign key.

I want to put them into a nested repeater, but I'm having problems finding a
"nice" way of doing it.

Can someone please point me in the direction of a tutorial or best practice
to achieve this?

Thanks in advance,

Duncanassign the "Items" table to the outter repeater, then in the
OnItemDataBound event handler:

switch (e.Item.ItemType){
case ListItemType.Item: case ListItemType.AlternatingItem:
Repeater ir = e.Item.FindControl("rptInnerRepeater")
ir.DataSource =
((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
ir.DataBind();
}

hope that helps
Thanks for your reply; I saw this example on the web, but I'm unsure where
the ItemDetailDataRelation comes from. I tried all the relationship names
that were in the strongly-typed dataset designer, but they gave an error.

I got the impression that if you were doing it between two datatables, that
would be the name of the Relations.Add(... but I couldn't seem to create a
programatic relationship between two fields in a strongly typed dataset.

Duncan

"bfking" <bfking@.gmail.com> wrote in message
news:1112879887.227421.298170@.g14g2000cwa.googlegr oups.com...
> assign the "Items" table to the outter repeater, then in the
> OnItemDataBound event handler:
> switch (e.Item.ItemType){
> case ListItemType.Item: case ListItemType.AlternatingItem:
> Repeater ir = e.Item.FindControl("rptInnerRepeater")
> ir.DataSource =
> ((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
> ir.DataBind();
> }
> hope that helps
The relation is set up in the dataset.

something like
_myDataSet.Relations.Add("Users_Results", _myDataSet.TableA.UsersNameColumn,
_myDataSet.TableB.UsersNameColumn);

where _myDataSet is your strongly typed DataSet.
in your nested Repeater you would then do something like this:

<asp:repeater id="_reportoutput" Runat="server"
...templates

//nested repeater
<asp:repeater id="_nextstuff" Runat="server" DataSource='<%#
GetChildRelation(Container.DataItem,"Users_Results")%>'
with the following in your code behind:

public static DataView GetChildRelation(object dataItem, string relation)
{
DataRowView drv = dataItem as DataRowView;
if (drv != null)

return drv.CreateChildView(relation);
else
return null;
}

MattC
"Duncan Welch" <dunc@.ntpcl.f9.co.uk> wrote in message
news:usyUFl3OFHA.984@.TK2MSFTNGP10.phx.gbl...
> Thanks for your reply; I saw this example on the web, but I'm unsure where
> the ItemDetailDataRelation comes from. I tried all the relationship names
> that were in the strongly-typed dataset designer, but they gave an error.
> I got the impression that if you were doing it between two datatables,
> that
> would be the name of the Relations.Add(... but I couldn't seem to create a
> programatic relationship between two fields in a strongly typed dataset.
> Duncan
> "bfking" <bfking@.gmail.com> wrote in message
> news:1112879887.227421.298170@.g14g2000cwa.googlegr oups.com...
>> assign the "Items" table to the outter repeater, then in the
>> OnItemDataBound event handler:
>>
>> switch (e.Item.ItemType){
>> case ListItemType.Item: case ListItemType.AlternatingItem:
>> Repeater ir = e.Item.FindControl("rptInnerRepeater")
>> ir.DataSource =
>> ((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
>> ir.DataBind();
>> }
>>
>> hope that helps
>>

Strongly typed datasets and nested repeaters

I have a strongly typed dataset that returns two tables - "items" and
"itemdetails". In the strongly-typed dataset designer, I've created a link
(relationship) between the two tables based on a foreign key.
I want to put them into a nested repeater, but I'm having problems finding a
"nice" way of doing it.
Can someone please point me in the direction of a tutorial or best practice
to achieve this?
Thanks in advance,
Duncanassign the "Items" table to the outter repeater, then in the
OnItemDataBound event handler:
switch (e.Item.ItemType){
case ListItemType.Item: case ListItemType.AlternatingItem:
Repeater ir = e.Item.FindControl("rptInnerRepeater")
ir.DataSource =
((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
ir.DataBind();
}
hope that helps
Thanks for your reply; I saw this example on the web, but I'm unsure where
the ItemDetailDataRelation comes from. I tried all the relationship names
that were in the strongly-typed dataset designer, but they gave an error.
I got the impression that if you were doing it between two datatables, that
would be the name of the Relations.Add(... but I couldn't seem to create a
programatic relationship between two fields in a strongly typed dataset.
Duncan
"bfking" <bfking@.gmail.com> wrote in message
news:1112879887.227421.298170@.g14g2000cwa.googlegroups.com...
> assign the "Items" table to the outter repeater, then in the
> OnItemDataBound event handler:
> switch (e.Item.ItemType){
> case ListItemType.Item: case ListItemType.AlternatingItem:
> Repeater ir = e.Item.FindControl("rptInnerRepeater")
> ir.DataSource =
> ((DataRowView)e.Item.DataItem).CreateChildView("ItemDetailDataRelation");
> ir.DataBind();
> }
> hope that helps
>
The relation is set up in the dataset.
something like
_myDataSet.Relations.Add("Users_Results", _myDataSet.TableA.UsersNameColumn,
_myDataSet.TableB.UsersNameColumn);
where _myDataSet is your strongly typed DataSet.
in your nested Repeater you would then do something like this:
<asp:repeater id="_reportoutput" Runat="server">
...templates
//nested repeater
<asp:repeater id="_nextstuff" Runat="server" DataSource='<%#
GetChildRelation(Container.DataItem,"Users_Results")%>'>
with the following in your code behind:
public static DataView GetChildRelation(object dataItem, string relation)
{
DataRowView drv = dataItem as DataRowView;
if (drv != null)
return drv.CreateChildView(relation);
else
return null;
}
MattC
"Duncan Welch" <dunc@.ntpcl.f9.co.uk> wrote in message
news:usyUFl3OFHA.984@.TK2MSFTNGP10.phx.gbl...
> Thanks for your reply; I saw this example on the web, but I'm unsure where
> the ItemDetailDataRelation comes from. I tried all the relationship names
> that were in the strongly-typed dataset designer, but they gave an error.
> I got the impression that if you were doing it between two datatables,
> that
> would be the name of the Relations.Add(... but I couldn't seem to create a
> programatic relationship between two fields in a strongly typed dataset.
> Duncan
> "bfking" <bfking@.gmail.com> wrote in message
> news:1112879887.227421.298170@.g14g2000cwa.googlegroups.com...
>

Strongly-Typed

Hi Folks,

Can someone please explain for me the term:Strongly-Typed please?

I recently heard about it a lot of times.

thanks in advance,

http://en.wikipedia.org/wiki/Strong_typing

Thanks, but it's too general for me.

I need maybe some example please.

Thank You.


ok. Look at this nice example

Strong vs. Weak typing

The division to strong and weak typed languages is much less clear-cut than static vs. dynamic, and there is a lot of confusion on what strong typing means. One common definition isdisallowing operations on incompatible types. Consider the following example from Perl (a weakly typed language):

print "2" + 4;

This code will print '6�� although it seemingly performs addition on incompatible types. This is because Perl is performing an implicit conversion when it sees we want to add a string that represents a number to another number. On the other hand, Ruby is strongly typed and the above statement will generate aTypeError.

More info:http://eli.thegreenplace.net/2006/11/25/a-taxonomy-of-typing-systems/


Ok...

I get something.

Thanks a lot.

Strongly-typed Datasets in ASP.NET 2.0

Hello,

In ASP.NET 1.1, I followed this data access methodology:

At design time
- Create a strongly typed dataset
- Add this dataset to a form and bind controls to the dataset using
the designer

At run time
- Fill dataset with data on the first load of the page
- Handle all Add/Edit/Delete operations against the in-memory copy
of my dataset
- Persist the dataset between postbacks in session
- Give users the ability to Save or Cancel changes, which either
persists the changes to the database or discards them.

It worked like a charm -- there were only two trips to the database --
in the very beginning and at the very end. In memory manipulations were
very fast. And, more importantly, my productivity was high because I
was able to use design features of the Visual Studio.

It seems that in 2005, if I were to pursue the same methodology, things
would be harder, not easier.

- It appears that the only way to bind a dataset to a gridview is
through the ObjectDataSource. This binds to table adapters, not the
actual dataset, so, the database gets hit on each update.

- DataSource property is gone from the design view, so I no longer can
use the design features of Visual Studio, if I were to directly bind to
a dataset.

- There is no out of the box feature to persist a dataset between
postbacks. So, like in 1.1, if I were to go this route, I would have to
persist it in session.

I was wondering if there is anybody out there who used the 1.1 data
access in a similar fashion, and how you adapted to 2.0.

Thank you for your comments.

Evgueni

Hi Evgueni,

You can create a strongly typed DS without table adapters also. Simplest way is to just open the DS in the designer and delete the adapter part. You can then use this DS to bind to a gridView (like in 1.1) but you need to manually write code to add rows to it. Alternatively, you can use an ObjectDatasource and let it handle the DB code itself.

HTH,

Vivek


Wouldn't that be great, if there was a data source object that would out of the box:

- bind directly to a dataset, not table adapters
- know how to persist the dataset between postbacks (maybe different persistence models such as session or cache)
- have the load and update methods to interact with the database

Basically, Windows Forms pattern -- but in a stateless environment. This would greatly assist us with creating cancellable forms such as wizard and complex master/child forms.

Am I talking non-sense, or is it something that people could use in ASP.NET?


Data source controls controls can either directly connect to a data store such as a DB or XML files, or to a business object (such as a strongly typed dataset). They act like a "broker" dealing with the manipulation of data so that the developer is spared of writing too much standard data access code. So an object data source can bind directly to a dataset (and you need to create a strongly typed dataset for it, or a custom business object) and also support caching. When using typed datasets, the VS 2005 designer creates TableAdapters for the Datasets, which is an advanced and quite useful feature considering the fact that TableAdapters extend DataAdpaters.

Now when we talk about binding directly to a dataset, this we can easily do, but tableAdapeters help us to avoid writing CRUD code (with the help of VS designer) and save time. You can very easily attach Load and Update methods using TableAdapter to bind to a particular table in the DB. So my point is that TableAdapters are just some "nitro boosted" form of DataAdapters, and while using them you are infact binding with the typed Datasets only.

Summarising, all your requirements can be easily met with the new ADO.NET and VS 2005 designer features in .NET 2.0.

Let me know if you need more details.

Vivek


Vivek, thank you for your response.

I understand that what I am asking for can be done in .NET 2.0. My point is that you actually have to write code if you want to bind directly to a dataset, and I don't want to do thatSmile. For example, I want to bind directly to the dataset, and maintain a full design-time experience like I had in 2003. I can't do that now because the Data Source property is not available in the designer. Am I missing something here?

Evgueni


Evgueni,

You can use the DataSource property for the GridView in the code behind, but the reason it is not there in the Properties window is due to the fact that if we bind a gridview to a non-datasourcecontrol object, we need to provide custom paging. So it is advisable to use an ObjectDataSource which is connected to a strongly typed dataset with a gridview. All relevant designer properties would be supported.

Let me know if you still face issues with this approach.

Vivek

Strongly-Typed State Class in UIAPB

I'm trying to use a strongly-typed State class in my UIAPB-based app.
It looks like state is being "over-persisted" if there is such a
thing. I'm using session state persistence.
I start a session, navigate a between a couple of different "UI
Processes", and then end it (even going as far as calling
Page.Session.Abandon() in the final page of my app.) I start a new
session, I see a new task Id, but information from the state from the
previous session is being picked up in the new session.
I have made sure that I complete all the UI tasks and that there are
no references (as far as I can tell) to the existing custom state
object when I end the session.
This is driving me nuts - any suggestions?
Thanks,
BryanOn Wed, 21 Sep 2005 11:37:38 -0500, bryan@.newsgroups.nospam wrote:
Nevermind. It was my being nuts in the first place that made me thing
something was wrong.

Strongly-Typed State Class in UIAPB

I'm trying to use a strongly-typed State class in my UIAPB-based app.
It looks like state is being "over-persisted" if there is such a
thing. I'm using session state persistence.

I start a session, navigate a between a couple of different "UI
Processes", and then end it (even going as far as calling
Page.Session.Abandon() in the final page of my app.) I start a new
session, I see a new task Id, but information from the state from the
previous session is being picked up in the new session.

I have made sure that I complete all the UI tasks and that there are
no references (as far as I can tell) to the existing custom state
object when I end the session.

This is driving me nuts - any suggestions?

Thanks,
BryanOn Wed, 21 Sep 2005 11:37:38 -0500, bryan@.newsgroups.nospam wrote:

Nevermind. It was my being nuts in the first place that made me thing
something was wrong.