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

Thursday, March 22, 2012

Strongly Type Web Forms

How does a User Control invoke a method on its parent page? Say I have a publicMethod in code behind for an aspx page:
...
public void SomeImportantMethod() { /* do important stuff */}
...
From an Event Handler within the User Control, I'd like to invoke a method on the page in which the User Control is embedded. If I stop in the debugger and inspect this.Page, I see that it has a type of "ASP.MyAspxPage"... where did that come from? Can I delcare it intentionally somewhere?
TIA,
Geo
Your MyAspxPage is your custom page class, which inherits from the System.Web.UI.Page class.
The thing with UserControls is though, that you don't know what parent page they could be in at run-time.
So, to be safe, if you want to call a particular method on the parentPage, I'd say let your Page implement your interface which contains themethod signature (and other stuff if you want).
In your UserControl you then do a defensive cast (using the as keyword)to that interface and check for != null. You then simply call yourmethod on your interface object.
Hope that helps.
Wim

Yes, that does help. It helped in that I was hung up in anold paradigm and should get over it and just use an interface. So, thanks, that helped me get the job done.
I guess I was stuck in theOLD ASP.NET 1.1 code behind days where an ASPX page would have a code behind page which had a namespace declaration and the web form would be a public class derived from System.Web.UI.Page. So, from any C# code I could say:
MyNamespace.MyPage myPage = this.Page as MyNameSpace.MyPage;
if ( myPage != null)
{
myPage.MyMethod("hello world");
}
else
{
Response.Write("what gives?");
}
No fuss no muss, no interfaces.
I think I better go find an article or 2 on code beside or what ever it is we call it now.
Thanks again,
geo

Hello.

I think that you can also use the @.reference directive to introduce the type of the page in the user control (haven't tried it though).

Strongly Type Datasets

I am trying to create a strongly typed dataset is VS 2005 with the VS
creating the stored procedures. It won't create the stored procedures. The
SQL script it generates is based on a SQL login so the script looks
something like:

DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE

these scripts won't work until I change the script to:

DROP PROCEDURE dbo.WEB_PAGE_UPDATE

What am I doing wrong? I suspect I doing my connectionstring wrong in some
way or my permissions are wrong in SQL Server.

Regards, Chris.Is there a setting for the database "Schema Name" somewhere on the
properties of the data set? That's what's being prepended to the table name.

"Chris" <nospam@.nospam.comwrote in message
news:OdiLaBGoHHA.4412@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>I am trying to create a strongly typed dataset is VS 2005 with the VS
>creating the stored procedures. It won't create the stored procedures. The
>SQL script it generates is based on a SQL login so the script looks
>something like:
>
DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE
>
these scripts won't work until I change the script to:
>
DROP PROCEDURE dbo.WEB_PAGE_UPDATE
>
What am I doing wrong? I suspect I doing my connectionstring wrong in some
way or my permissions are wrong in SQL Server.
>
Regards, Chris.
>


No I can't find it. Any clues where abouts I might find it. I have looked on
the properties on of the dataset etc.

"KJ" <n_o_s_p_a__M@.Mail.comwrote in message
news:OFjUR$GoHHA.716@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Is there a setting for the database "Schema Name" somewhere on the
properties of the data set? That's what's being prepended to the table
name.
>
"Chris" <nospam@.nospam.comwrote in message
news:OdiLaBGoHHA.4412@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>>I am trying to create a strongly typed dataset is VS 2005 with the VS
>>creating the stored procedures. It won't create the stored procedures. The
>>SQL script it generates is based on a SQL login so the script looks
>>something like:
>>
>DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE
>>
>these scripts won't work until I change the script to:
>>
>DROP PROCEDURE dbo.WEB_PAGE_UPDATE
>>
>What am I doing wrong? I suspect I doing my connectionstring wrong in
>some way or my permissions are wrong in SQL Server.
>>
>Regards, Chris.
>>


>
>


Which version of SQL Server? If 2005, go to the properties page of the login
you are using (via Management Studio), and check the value for Default
Schema for that login. My guess is that it's not dbo. But this is just a
guess.

"Chris" <nospam@.nospam.comwrote in message
news:OxkTYdHoHHA.4124@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

No I can't find it. Any clues where abouts I might find it. I have looked
on the properties on of the dataset etc.
>
"KJ" <n_o_s_p_a__M@.Mail.comwrote in message
news:OFjUR$GoHHA.716@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

>Is there a setting for the database "Schema Name" somewhere on the
>properties of the data set? That's what's being prepended to the table
>name.
>>
>"Chris" <nospam@.nospam.comwrote in message
>news:OdiLaBGoHHA.4412@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>>>I am trying to create a strongly typed dataset is VS 2005 with the VS
>>>creating the stored procedures. It won't create the stored procedures.
>>>The SQL script it generates is based on a SQL login so the script looks
>>>something like:
>>>
>>DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE
>>>
>>these scripts won't work until I change the script to:
>>>
>>DROP PROCEDURE dbo.WEB_PAGE_UPDATE
>>>
>>What am I doing wrong? I suspect I doing my connectionstring wrong in
>>some way or my permissions are wrong in SQL Server.
>>>
>>Regards, Chris.
>>>


>>
>>


>
>


Sorry I must be missing something. When you say "check for default schema",
I can't find it it. It is SQL 2005. I have gone to the login propeties page
of the login (in SQL 2005), gone to user mapping and put the default scheme
over to do_owner but the sql scripts generated are still this same in VS
2005

"KJ" <n_o_s_p_a__M@.Mail.comwrote in message
news:O7IrnYJoHHA.1476@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Which version of SQL Server? If 2005, go to the properties page of the
login you are using (via Management Studio), and check the value for
Default Schema for that login. My guess is that it's not dbo. But this is
just a guess.
>
"Chris" <nospam@.nospam.comwrote in message
news:OxkTYdHoHHA.4124@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>No I can't find it. Any clues where abouts I might find it. I have looked
>on the properties on of the dataset etc.
>>
>"KJ" <n_o_s_p_a__M@.Mail.comwrote in message
>news:OFjUR$GoHHA.716@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

>>Is there a setting for the database "Schema Name" somewhere on the
>>properties of the data set? That's what's being prepended to the table
>>name.
>>>
>>"Chris" <nospam@.nospam.comwrote in message
>>news:OdiLaBGoHHA.4412@.TK2MSFTNGP02.phx.gbl...
>>I am trying to create a strongly typed dataset is VS 2005 with the VS
>>creating the stored procedures. It won't create the stored procedures.
>>The SQL script it generates is based on a SQL login so the script looks
>>something like:
>>
>>>DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE
>>
>>>these scripts won't work until I change the script to:
>>
>>>DROP PROCEDURE dbo.WEB_PAGE_UPDATE
>>
>>>What am I doing wrong? I suspect I doing my connectionstring wrong in
>>>some way or my permissions are wrong in SQL Server.
>>
>>>Regards, Chris.
>>
>>>
>>>


>>
>>


>
>


"db_owner" is a role, not a schema; "dbo" is a schema.

When you look at the name of the table in the Object Explorer (of Management
Studio), what is it? Is it dbo.TableName, or WebManagerV2.TableName?

"Chris" <nospam@.nospam.comwrote in message
news:O7PiG6KoHHA.5052@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

Sorry I must be missing something. When you say "check for default
schema", I can't find it it. It is SQL 2005. I have gone to the login
propeties page of the login (in SQL 2005), gone to user mapping and put
the default scheme over to do_owner but the sql scripts generated are
still this same in VS 2005
>
>
"KJ" <n_o_s_p_a__M@.Mail.comwrote in message
news:O7IrnYJoHHA.1476@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>Which version of SQL Server? If 2005, go to the properties page of the
>login you are using (via Management Studio), and check the value for
>Default Schema for that login. My guess is that it's not dbo. But this is
>just a guess.
>>
>"Chris" <nospam@.nospam.comwrote in message
>news:OxkTYdHoHHA.4124@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>>No I can't find it. Any clues where abouts I might find it. I have
>>looked on the properties on of the dataset etc.
>>>
>>"KJ" <n_o_s_p_a__M@.Mail.comwrote in message
>>news:OFjUR$GoHHA.716@.TK2MSFTNGP05.phx.gbl...
>>>Is there a setting for the database "Schema Name" somewhere on the
>>>properties of the data set? That's what's being prepended to the table
>>>name.
>>
>>>"Chris" <nospam@.nospam.comwrote in message
>>>news:OdiLaBGoHHA.4412@.TK2MSFTNGP02.phx.gbl...
>>I am trying to create a strongly typed dataset is VS 2005 with the VS
>>creating the stored procedures. It won't create the stored procedures.
>>The SQL script it generates is based on a SQL login so the script looks
>>something like:
>>
>>DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE
>>
>>these scripts won't work until I change the script to:
>>
>>DROP PROCEDURE dbo.WEB_PAGE_UPDATE
>>
>>What am I doing wrong? I suspect I doing my connectionstring wrong in
>>some way or my permissions are wrong in SQL Server.
>>
>>Regards, Chris.
>>
>>
>>
>>>
>>>


>>
>>


>
>

Strongly Type Datasets

I am trying to create a strongly typed dataset is VS 2005 with the VS
creating the stored procedures. It won't create the stored procedures. The
SQL script it generates is based on a SQL login so the script looks
something like:
DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE
these scripts won't work until I change the script to:
DROP PROCEDURE dbo.WEB_PAGE_UPDATE
What am I doing wrong? I suspect I doing my connectionstring wrong in some
way or my permissions are wrong in SQL Server.
Regards, Chris.Is there a setting for the database "Schema Name" somewhere on the
properties of the data set? That's what's being prepended to the table name.
"Chris" <nospam@.nospam.com> wrote in message
news:OdiLaBGoHHA.4412@.TK2MSFTNGP02.phx.gbl...
>I am trying to create a strongly typed dataset is VS 2005 with the VS
>creating the stored procedures. It won't create the stored procedures. The
>SQL script it generates is based on a SQL login so the script looks
>something like:
> DROP PROCEDURE WebManagerV2.WEB_PAGE_UPDATE
> these scripts won't work until I change the script to:
> DROP PROCEDURE dbo.WEB_PAGE_UPDATE
> What am I doing wrong? I suspect I doing my connectionstring wrong in some
> way or my permissions are wrong in SQL Server.
> Regards, Chris.
>
Which version of SQL Server? If 2005, go to the properties page of the login
you are using (via Management Studio), and check the value for Default
Schema for that login. My guess is that it's not dbo. But this is just a
guess.
"Chris" <nospam@.nospam.com> wrote in message
news:OxkTYdHoHHA.4124@.TK2MSFTNGP02.phx.gbl...
> No I can't find it. Any clues where abouts I might find it. I have looked
> on the properties on of the dataset etc.
> "KJ" <n_o_s_p_a__M@.Mail.com> wrote in message
> news:OFjUR$GoHHA.716@.TK2MSFTNGP05.phx.gbl...
>
No I can't find it. Any clues where abouts I might find it. I have looked on
the properties on of the dataset etc.
"KJ" <n_o_s_p_a__M@.Mail.com> wrote in message
news:OFjUR$GoHHA.716@.TK2MSFTNGP05.phx.gbl...
> Is there a setting for the database "Schema Name" somewhere on the
> properties of the data set? That's what's being prepended to the table
> name.
> "Chris" <nospam@.nospam.com> wrote in message
> news:OdiLaBGoHHA.4412@.TK2MSFTNGP02.phx.gbl...
>
Sorry I must be missing something. When you say "check for default schema",
I can't find it it. It is SQL 2005. I have gone to the login propeties page
of the login (in SQL 2005), gone to user mapping and put the default scheme
over to do_owner but the sql scripts generated are still this same in VS
2005
"KJ" <n_o_s_p_a__M@.Mail.com> wrote in message
news:O7IrnYJoHHA.1476@.TK2MSFTNGP03.phx.gbl...
> Which version of SQL Server? If 2005, go to the properties page of the
> login you are using (via Management Studio), and check the value for
> Default Schema for that login. My guess is that it's not dbo. But this is
> just a guess.
> "Chris" <nospam@.nospam.com> wrote in message
> news:OxkTYdHoHHA.4124@.TK2MSFTNGP02.phx.gbl...
>
"db_owner" is a role, not a schema; "dbo" is a schema.
When you look at the name of the table in the Object Explorer (of Management
Studio), what is it? Is it dbo.TableName, or WebManagerV2.TableName?
"Chris" <nospam@.nospam.com> wrote in message
news:O7PiG6KoHHA.5052@.TK2MSFTNGP04.phx.gbl...
> Sorry I must be missing something. When you say "check for default
> schema", I can't find it it. It is SQL 2005. I have gone to the login
> propeties page of the login (in SQL 2005), gone to user mapping and put
> the default scheme over to do_owner but the sql scripts generated are
> still this same in VS 2005
>
> "KJ" <n_o_s_p_a__M@.Mail.com> wrote in message
> news:O7IrnYJoHHA.1476@.TK2MSFTNGP03.phx.gbl...
>
http://Pamela-Anderson-in-nylons.in...p?movie=1673286

Strongly Typed Collection - sort in DataGrid

Assume you have a strongly typed collection of a class called Person. The
strongly typed collection implements IEnumerable so it can be databound to a
server control like a DataGrid. The Person class has several public
properties like FirstName, LastName, and Gender.
What steps would it take to allow the collection to be sorted using a
DataGrid?
Thanks in advance.
MarkHere is a great resource for implementing sorting for the datagrid:
http://msdn.microsoft.com/library/d...dWebControl.asp
"Mark" wrote:

> Assume you have a strongly typed collection of a class called Person. The
> strongly typed collection implements IEnumerable so it can be databound to
a
> server control like a DataGrid. The Person class has several public
> properties like FirstName, LastName, and Gender.
> What steps would it take to allow the collection to be sorted using a
> DataGrid?
> Thanks in advance.
> Mark
>
>

Strongly Typed Collections

I'm writing a web service that I want to return a strongly typed collection.
If I inherit System.collections.generic.list(of T) it returns an ArrayOfT.
If I inherit CollectionsBase, it also returns an ArrayOf. I want the root
xml element to just be of the class itself (if that makes any sense). Is
this even possible? What do I need to inherit?
If you want a strong object/collection on the outside world (of a web
service)...then the client needs to know something about some kind of strong
collection.
..
Take a look here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!158.entry
I have a IZebraCollection......which the service and the host know about.
Its WCF, but WCF can be exposed as a webservice.
..
"Dave T" <DaveT@.discussions.microsoft.com> wrote in message
news:A1A6AA44-6974-4B5C-9C11-795D570F46A7@.microsoft.com...
> I'm writing a web service that I want to return a strongly typed
> collection.
> If I inherit System.collections.generic.list(of T) it returns an ArrayOfT.
> If I inherit CollectionsBase, it also returns an ArrayOf. I want the root
> xml element to just be of the class itself (if that makes any sense). Is
> this even possible? What do I need to inherit?

Strongly typed dataset

I have started using strongly typed datasets as the basis of my data access
layer. They work well but can be a bit fiddly when adding columns. I have a
column which refuses to "change". It is an integer which when I change its
value in the datatable it changes from 1 to 2 (I can see it in the
debugger). When I call the update method it resets back to 1.
Does anyone have any ideas. I don't want to recreate my DAL object without
knowing what I have done wrong. Ideally I would like to just recreate all my
stored procedures but doing that seems to "append columns" to the dataset in
the design view.
If I add some columns to my database what is the best way of regenerating
all the stored procedure and the column names for the strongly typed
dataset.
Regards, Chris."Chris" <nospam@.nospam.com> wrote in message
news:ulPXy7LnHHA.4120@.TK2MSFTNGP06.phx.gbl...
>I have started using strongly typed datasets as the basis of my data access
>layer. They work well but can be a bit fiddly when adding columns. I have a
>column which refuses to "change". It is an integer which when I change its
>value in the datatable it changes from 1 to 2 (I can see it in the
>debugger). When I call the update method it resets back to 1.
> Does anyone have any ideas. I don't want to recreate my DAL object without
> knowing what I have done wrong. Ideally I would like to just recreate all
> my stored procedures but doing that seems to "append columns" to the
> dataset in the design view.
> If I add some columns to my database what is the best way of regenerating
> all the stored procedure and the column names for the strongly typed
> dataset.
I don't know the answer to your problem, but here's a hint: DataSets don't
write to the database. Look at the parts that do. You may find, for
instance, that it isn't that the column is being reset to 1, but that it
isn't being set to 2.
--
John Saunders [MVP]

Strongly Typed dataset

Hello,

I have a typed dataset defined in my project. I am writing a user control
which needs to invoke an instance of that dataset. Problem is that the page
developer only provides the name of the dataset to my user control.
I want my user control to invoke an instance of that dataset from its
"string" representation of the type.
I used type.gettype("Mydatasettype") , but ctype function would not accept
it as a valid type.

Any help is appreciated.Like any other compiled class the generated strongly-typed DataSet can be
accessed by System.Reflection at run-time. The easiest way to do this is
probably with the Activator.CreateInstance(..) method, but I'm fairly
certain you'll have to load the Assembly that has the DataSet in it manually
(if it's not already loaded - you'll have to check for that as well).

Does that help?
Richard
--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Imran" <imran_halim@.hotmail.com> wrote in message
news:On5uAAX4DHA.488@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a typed dataset defined in my project. I am writing a user control
> which needs to invoke an instance of that dataset. Problem is that the
page
> developer only provides the name of the dataset to my user control.
> I want my user control to invoke an instance of that dataset from its
> "string" representation of the type.
> I used type.gettype("Mydatasettype") , but ctype function would not accept
> it as a valid type.
> Any help is appreciated.

Strongly typed dataset

I have started using strongly typed datasets as the basis of my data access
layer. They work well but can be a bit fiddly when adding columns. I have a
column which refuses to "change". It is an integer which when I change its
value in the datatable it changes from 1 to 2 (I can see it in the
debugger). When I call the update method it resets back to 1.

Does anyone have any ideas. I don't want to recreate my DAL object without
knowing what I have done wrong. Ideally I would like to just recreate all my
stored procedures but doing that seems to "append columns" to the dataset in
the design view.

If I add some columns to my database what is the best way of regenerating
all the stored procedure and the column names for the strongly typed
dataset.

Regards, Chris."Chris" <nospam@.nospam.comwrote in message
news:ulPXy7LnHHA.4120@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

>I have started using strongly typed datasets as the basis of my data access
>layer. They work well but can be a bit fiddly when adding columns. I have a
>column which refuses to "change". It is an integer which when I change its
>value in the datatable it changes from 1 to 2 (I can see it in the
>debugger). When I call the update method it resets back to 1.
>
Does anyone have any ideas. I don't want to recreate my DAL object without
knowing what I have done wrong. Ideally I would like to just recreate all
my stored procedures but doing that seems to "append columns" to the
dataset in the design view.
>
If I add some columns to my database what is the best way of regenerating
all the stored procedure and the column names for the strongly typed
dataset.


I don't know the answer to your problem, but here's a hint: DataSets don't
write to the database. Look at the parts that do. You may find, for
instance, that it isn't that the column is being reset to 1, but that it
isn't being set to 2.
--
John Saunders [MVP]

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 datasets and XML

I am having trouble understanding strongly typed datasets and XML files. I
have the following schema:

<xs:schema id="Pages" targetNamespace="http://asdf.org/EOBEPages.xsd"
elementFormDefault="qualified"
xmlns="http://asdf.org" xmlns:mstns="http://asdf.org/EOBEPages.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="EOBEPages">
<xs:complexType>
<xs:sequence>
<xs:element name="Page">
<xs:complexType>
<xs:sequence>
<xs:element name="PageTitle" type="xs:string" />
<xs:element name="PageText" type="xs:string" />
<xs:element name="PageNumber" type="xs:integer" />
<xs:element name="NumImages" type="xs:integer" />
<xs:element name="ImagesDescription" type="xs:string" minOccurs="0"
maxOccurs="1" />
<xs:element name="ImageDefinitions">
<xs:complexType>
<xs:sequence>
<xs:element name="Description" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema
I load the xml data into the dataset no problem, and can access the "page"
info by:

myDataset.Page(index).pageTitle

, etc, but can NOT access the "ImageDefinitions", because I guess I don't
understand how. What I wanted to do is something like:

myVar = myDataset.Page(index).ImageDefinitions(index2).Des cription

but this is not part of the dataset... why? How can I get access to the
image definition descriptions based on the page index?

Thanks a bunch!

MC Ddatasets are tables with relationships. every xml complex type becomes a new
table. ImageDefinitions becomes a table which you can access.

myVar = myDataset.ImageDefinitions(index).Description

if you have a relionship setup you can access ImageDefinitions rows from
Page rows using GetChildRows

-- bruce (sqlwork.com)

"Big D" <a@.a.com> wrote in message
news:uam6WMY9DHA.1632@.TK2MSFTNGP12.phx.gbl...
> I am having trouble understanding strongly typed datasets and XML files.
I
> have the following schema:
> <xs:schema id="Pages" targetNamespace="http://asdf.org/EOBEPages.xsd"
> elementFormDefault="qualified"
> xmlns="http://asdf.org" xmlns:mstns="http://asdf.org/EOBEPages.xsd"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:element name="EOBEPages">
> <xs:complexType>
> <xs:sequence
> <xs:element name="Page">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="PageTitle" type="xs:string" />
> <xs:element name="PageText" type="xs:string" />
> <xs:element name="PageNumber" type="xs:integer" />
> <xs:element name="NumImages" type="xs:integer" />
> <xs:element name="ImagesDescription" type="xs:string" minOccurs="0"
> maxOccurs="1" /
> <xs:element name="ImageDefinitions">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="Description" type="xs:string" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
> I load the xml data into the dataset no problem, and can access the "page"
> info by:
> myDataset.Page(index).pageTitle
> , etc, but can NOT access the "ImageDefinitions", because I guess I don't
> understand how. What I wanted to do is something like:
> myVar = myDataset.Page(index).ImageDefinitions(index2).Des cription
> but this is not part of the dataset... why? How can I get access to the
> image definition descriptions based on the page index?
> Thanks a bunch!
> MC D

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