473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Put value from DataList on user control to parent page?

I have a user control (menu) with a data list:

<asp:DataList id="MyList" runat="server">
<ItemTemplate>
<asp:hyperlink
cssclass="MenuUnselected"
id="myLink1"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</ItemTemplate>
<SelectedItemTemplate>
<asp:hyperlink
cssclass="MenuSelected"
id="myLink2"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</SelectedItemTemplate>
</asp:DataList>

I want to take the value of the Text attribute (the data item:
"Subject") from the selected item and put it in a label on the parent
page. I have spent a day and a half trying this, so I decided to ask
if anyone out there can help me. Thanks!
Nov 17 '05 #1
6 1903
"Mary Kerrigan" <mk*******@ktoys.com> wrote in message
news:65**************************@posting.google.c om...
I have a user control (menu) with a data list:

<asp:DataList id="MyList" runat="server">
<ItemTemplate>
<asp:hyperlink
cssclass="MenuUnselected"
id="myLink1"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</ItemTemplate>
<SelectedItemTemplate>
<asp:hyperlink
cssclass="MenuSelected"
id="myLink2"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</SelectedItemTemplate>
</asp:DataList>

I want to take the value of the Text attribute (the data item:
"Subject") from the selected item and put it in a label on the parent
page. I have spent a day and a half trying this, so I decided to ask
if anyone out there can help me. Thanks!


With ASP.NET, it's best to think a bit object-oriented.

So, why should your user control know anything about the page it happens to
be loaded into? In particular, why should it know that there's a label on
that page? Answer: it shouldn't.

On the other hand, the user control does know about the Text attribute of
the selected item. You could define a public property in the user control
which would expose that Text attribute so that any containing page (or other
control) can see the value of the Text attribute.

If the surrounding page needs to know when the selected index has changed
(so that it knows to fetch the Text property) then you can define a public
event in your user control and raise it when the user control receives the
SelectedIndexChanged event.
--
John
Nov 17 '05 #2
OK - I know how to assign a value to the public property, but what I
can't figure out is the syntax to retrieve the Text attribute's value
for the selected item. ???

"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<Of**************@TK2MSFTNGP10.phx.gbl>...
"Mary Kerrigan" <mk*******@ktoys.com> wrote in message
news:65**************************@posting.google.c om...
I have a user control (menu) with a data list:

<asp:DataList id="MyList" runat="server">
<ItemTemplate>
<asp:hyperlink
cssclass="MenuUnselected"
id="myLink1"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</ItemTemplate>
<SelectedItemTemplate>
<asp:hyperlink
cssclass="MenuSelected"
id="myLink2"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</SelectedItemTemplate>
</asp:DataList>

I want to take the value of the Text attribute (the data item:
"Subject") from the selected item and put it in a label on the parent
page. I have spent a day and a half trying this, so I decided to ask
if anyone out there can help me. Thanks!


With ASP.NET, it's best to think a bit object-oriented.

So, why should your user control know anything about the page it happens to
be loaded into? In particular, why should it know that there's a label on
that page? Answer: it shouldn't.

On the other hand, the user control does know about the Text attribute of
the selected item. You could define a public property in the user control
which would expose that Text attribute so that any containing page (or other
control) can see the value of the Text attribute.

If the surrounding page needs to know when the selected index has changed
(so that it knows to fetch the Text property) then you can define a public
event in your user control and raise it when the user control receives the
SelectedIndexChanged event.

Nov 17 '05 #3
Here's one thing I have tried which didn't work:

Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyList.SelectedIndexChanged

Dim myListItem As DataListItem = CType(sender,
DataList).SelectedItem
Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
Dim myValue As String = myHyperlink.Text
lblTest.Text = myValue

End Sub


mk*******@ktoys.com (Mary Kerrigan) wrote in message news:<65**************************@posting.google. com>...
OK - I know how to assign a value to the public property, but what I
can't figure out is the syntax to retrieve the Text attribute's value
for the selected item. ???

"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<Of**************@TK2MSFTNGP10.phx.gbl>...
"Mary Kerrigan" <mk*******@ktoys.com> wrote in message
news:65**************************@posting.google.c om...
I have a user control (menu) with a data list:

<asp:DataList id="MyList" runat="server">
<ItemTemplate>
<asp:hyperlink
cssclass="MenuUnselected"
id="myLink1"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</ItemTemplate>
<SelectedItemTemplate>
<asp:hyperlink
cssclass="MenuSelected"
id="myLink2"
Text='<%# Container.DataItem("Subject") %>'
NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex
%>'
runat="server" />
</SelectedItemTemplate>
</asp:DataList>

I want to take the value of the Text attribute (the data item:
"Subject") from the selected item and put it in a label on the parent
page. I have spent a day and a half trying this, so I decided to ask
if anyone out there can help me. Thanks!


With ASP.NET, it's best to think a bit object-oriented.

So, why should your user control know anything about the page it happens to
be loaded into? In particular, why should it know that there's a label on
that page? Answer: it shouldn't.

On the other hand, the user control does know about the Text attribute of
the selected item. You could define a public property in the user control
which would expose that Text attribute so that any containing page (or other
control) can see the value of the Text attribute.

If the surrounding page needs to know when the selected index has changed
(so that it knows to fetch the Text property) then you can define a public
event in your user control and raise it when the user control receives the
SelectedIndexChanged event.

Nov 17 '05 #4
"Didn't work" how?

--
John

"Mary Kerrigan" <mk*******@ktoys.com> wrote in message
news:65**************************@posting.google.c om...
Here's one thing I have tried which didn't work:

Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyList.SelectedIndexChanged

Dim myListItem As DataListItem = CType(sender,
DataList).SelectedItem
Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
Dim myValue As String = myHyperlink.Text
lblTest.Text = myValue

End Sub


mk*******@ktoys.com (Mary Kerrigan) wrote in message

news:<65**************************@posting.google. com>...
OK - I know how to assign a value to the public property, but what I
can't figure out is the syntax to retrieve the Text attribute's value
for the selected item. ???

"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<Of**************@TK2MSFTNGP10.phx.gbl>...
"Mary Kerrigan" <mk*******@ktoys.com> wrote in message
news:65**************************@posting.google.c om...
> I have a user control (menu) with a data list:
>
> <asp:DataList id="MyList" runat="server">
> <ItemTemplate>
> <asp:hyperlink
> cssclass="MenuUnselected"
> id="myLink1"
> Text='<%# Container.DataItem("Subject") %>'
> NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex > %>'
> runat="server" />
> </ItemTemplate>
> <SelectedItemTemplate>
> <asp:hyperlink
> cssclass="MenuSelected"
> id="myLink2"
> Text='<%# Container.DataItem("Subject") %>'
> NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex > %>'
> runat="server" />
> </SelectedItemTemplate>
> </asp:DataList>
>
> I want to take the value of the Text attribute (the data item:
> "Subject") from the selected item and put it in a label on the parent > page. I have spent a day and a half trying this, so I decided to ask > if anyone out there can help me. Thanks!

With ASP.NET, it's best to think a bit object-oriented.

So, why should your user control know anything about the page it happens to be loaded into? In particular, why should it know that there's a label on that page? Answer: it shouldn't.

On the other hand, the user control does know about the Text attribute of the selected item. You could define a public property in the user control which would expose that Text attribute so that any containing page (or other control) can see the value of the Text attribute.

If the surrounding page needs to know when the selected index has changed (so that it knows to fetch the Text property) then you can define a public event in your user control and raise it when the user control receives the SelectedIndexChanged event.

Nov 17 '05 #5
Nothing happened - the label was blank instead of showing the value of
the Text attribute of Hyperlink2.

But now I think that's because this is in a user control. The
SelectedIndexChanged does not appear to fire at all. I think it's
because the user control does not postback???

It looks like I will have to go back to the database to get the value
I need when the page reloads... I didn't want to have to do this, you
would think I could get the value from the control, geez, it's right
there on the screen...

"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<O7**************@TK2MSFTNGP12.phx.gbl>...
"Didn't work" how?

--
John

"Mary Kerrigan" <mk*******@ktoys.com> wrote in message
news:65**************************@posting.google.c om...
Here's one thing I have tried which didn't work:

Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyList.SelectedIndexChanged

Dim myListItem As DataListItem = CType(sender,
DataList).SelectedItem
Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
Dim myValue As String = myHyperlink.Text
lblTest.Text = myValue

End Sub


mk*******@ktoys.com (Mary Kerrigan) wrote in message

news:<65**************************@posting.google. com>...
OK - I know how to assign a value to the public property, but what I
can't figure out is the syntax to retrieve the Text attribute's value
for the selected item. ???

"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<Of**************@TK2MSFTNGP10.phx.gbl>... > "Mary Kerrigan" <mk*******@ktoys.com> wrote in message
> news:65**************************@posting.google.c om...
> > I have a user control (menu) with a data list:
> >
> > <asp:DataList id="MyList" runat="server">
> > <ItemTemplate>
> > <asp:hyperlink
> > cssclass="MenuUnselected"
> > id="myLink1"
> > Text='<%# Container.DataItem("Subject") %>'
> > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex > > %>'
> > runat="server" />
> > </ItemTemplate>
> > <SelectedItemTemplate>
> > <asp:hyperlink
> > cssclass="MenuSelected"
> > id="myLink2"
> > Text='<%# Container.DataItem("Subject") %>'
> > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex > > %>'
> > runat="server" />
> > </SelectedItemTemplate>
> > </asp:DataList>
> >
> > I want to take the value of the Text attribute (the data item:
> > "Subject") from the selected item and put it in a label on the parent > > page. I have spent a day and a half trying this, so I decided to ask > > if anyone out there can help me. Thanks!
>
> With ASP.NET, it's best to think a bit object-oriented.
>
> So, why should your user control know anything about the page it happens to > be loaded into? In particular, why should it know that there's a label on > that page? Answer: it shouldn't.
>
> On the other hand, the user control does know about the Text attribute of > the selected item. You could define a public property in the user control > which would expose that Text attribute so that any containing page (or other > control) can see the value of the Text attribute.
>
> If the surrounding page needs to know when the selected index has changed > (so that it knows to fetch the Text property) then you can define a public > event in your user control and raise it when the user control receives the > SelectedIndexChanged event.

Nov 17 '05 #6
I have never found an answer to this problem... can anyone please help?
mk*******@ktoys.com (Mary Kerrigan) wrote in message news:<65**************************@posting.google. com>...
Nothing happened - the label was blank instead of showing the value of
the Text attribute of Hyperlink2.

But now I think that's because this is in a user control. The
SelectedIndexChanged does not appear to fire at all. I think it's
because the user control does not postback???

It looks like I will have to go back to the database to get the value
I need when the page reloads... I didn't want to have to do this, you
would think I could get the value from the control, geez, it's right
there on the screen...

"John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<O7**************@TK2MSFTNGP12.phx.gbl>...
"Didn't work" how?

--
John

"Mary Kerrigan" <mk*******@ktoys.com> wrote in message
news:65**************************@posting.google.c om...
Here's one thing I have tried which didn't work:

Private Sub MyList_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyList.SelectedIndexChanged

Dim myListItem As DataListItem = CType(sender,
DataList).SelectedItem
Dim myHyperlink As HyperLink = myListItem.FindControl("Hyperlink2")
Dim myValue As String = myHyperlink.Text
lblTest.Text = myValue

End Sub


mk*******@ktoys.com (Mary Kerrigan) wrote in message news:<65**************************@posting.google. com>... > OK - I know how to assign a value to the public property, but what I
> can't figure out is the syntax to retrieve the Text attribute's value
> for the selected item. ???
>
> "John Saunders" <john.saunders at surfcontrol.com> wrote in message news:<Of**************@TK2MSFTNGP10.phx.gbl>... > > "Mary Kerrigan" <mk*******@ktoys.com> wrote in message
> > news:65**************************@posting.google.c om...
> > > I have a user control (menu) with a data list:
> > >
> > > <asp:DataList id="MyList" runat="server">
> > > <ItemTemplate>
> > > <asp:hyperlink
> > > cssclass="MenuUnselected"
> > > id="myLink1"
> > > Text='<%# Container.DataItem("Subject") %>'
> > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex > > > %>'
> > > runat="server" />
> > > </ItemTemplate>
> > > <SelectedItemTemplate>
> > > <asp:hyperlink
> > > cssclass="MenuSelected"
> > > id="myLink2"
> > > Text='<%# Container.DataItem("Subject") %>'
> > > NavigateUrl='<%# "../productlist.aspx?SubjectID=" &
> > > Container.DataItem("SubjectID") & "&selection=" & Container.ItemIndex > > > %>'
> > > runat="server" />
> > > </SelectedItemTemplate>
> > > </asp:DataList>
> > >
> > > I want to take the value of the Text attribute (the data item:
> > > "Subject") from the selected item and put it in a label on the parent > > > page. I have spent a day and a half trying this, so I decided to ask > > > if anyone out there can help me. Thanks!
> >
> > With ASP.NET, it's best to think a bit object-oriented.
> >
> > So, why should your user control know anything about the page it happens to > > be loaded into? In particular, why should it know that there's a label on > > that page? Answer: it shouldn't.
> >
> > On the other hand, the user control does know about the Text attribute of > > the selected item. You could define a public property in the user control > > which would expose that Text attribute so that any containing page (or other > > control) can see the value of the Text attribute.
> >
> > If the surrounding page needs to know when the selected index has changed > > (so that it knows to fetch the Text property) then you can define a public > > event in your user control and raise it when the user control receives the > > SelectedIndexChanged event.

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wsyeager36 | last post by:
I have a datagrid inside a datalist. The datalist shows parent info and the datagrid shows the child info for that parent. There is a checkbox on each row of the child datagrid. Also inside the...
1
by: DotNetJunkies User | last post by:
Hi, I was wondering if it is possible to load datagrid into datalist programatically using ITemplate interface with the following structure and place intp placeholder control. PlaceHolder -...
3
by: Tillman Erb | last post by:
Let's assume a database with a parent table and a child table in a one-to-many relationship, respectively. I have a DataList control on page P that displays values from the parent table. Each row...
1
by: AndrewR | last post by:
Hey all, Have a strange one here I don't understand.... I have a DataList control in an .aspx page. Inside the DataList's <ItemTemplate> is a single LinkButton control. On the initial page...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
0
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView (databound using another ObjectDataSource2 contained in...
3
by: mroffey | last post by:
Hi everyone, I've been having this problem and I've searched high and low, but I can't seem to find the answer to what is probably a very simple solution. In a nutshell, I have a nested...
2
by: zb | last post by:
Scenario: I have a datalist control bound to a datasource. By itself, this works just fine. Now, inside the ItemTemplate I have a custom user control (I wrote this user control) and it has an...
1
by: berny.zamora | last post by:
Hello everyone, I have a composite control (lets call it the parent) that contains a datalist. The datalist has an ItemTemplate that contains another composite control (lets call it the child)....
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.