Monday, March 26, 2012
Newbie Alert: Please help with repeater control and list box
I am new to asp.net!
I can create a repeater control but would like to add a select list to
it as follows:
<%@dotnet.itags.org. Page Language="vb" debug=true %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<script runat="server"
Sub Page_Load(sender As Object, e As EventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
myConnection = New SqlConnection("server=local;user
id=whocares;database=dbSeekersClientApp;Trusted_Co nnection=false")
myCommand = New SqlDataAdapter("SELECT ID, username, password,
firstname, surname, account_live FROM t_managers", myConnection)
Dim ds As Dataset = new DataSet()
myCommand.Fill(ds)
MyRepeater.DataSource = ds
MyRepeater.DataBind()
End SUb
</script>
<html>
<head>
</head>
<body
<form action="intro1.aspx" method="post" runat="server"
<ASP:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 8pt verdana">
<tr style="background-color:DFA894">
<th>
User ID
</th>
<th>
Surname
</th>
<th>
Firstname
</th>
<th>
Username
</th>
<th>
Password
</th>
<th>
Access
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FFECD8">
<td>
<%# DataBinder.Eval(Container.DataItem, "ID") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "surname")
%>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"firstname") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"username") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"password") %>
</td>
<td>
>>>>> Problem code
<asp:DropDownList id="dList1" width=100 runat="server">
<option
value=<%#DataBinder.Eval(Container.DataItem, "account_live")%>>
<%# DataBinder.Eval(Container.DataItem, "account_live") %>
</option>
>>>> Problem code ends
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</ASP:Repeater>
</form>
</body>
</html
Any pointers?Your post went unanswered. Have you resolved this issue?
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"John sorCrer" <info@.emap.co.za> wrote in message
news:d70138e4.0403021226.36b59c74@.posting.google.c om...
> Hi Guru's,
> I am new to asp.net!
> I can create a repeater control but would like to add a select list to
> it as follows:
> <%@. Page Language="vb" debug=true %>
> <%@. import Namespace="System.Data" %>
> <%@. import Namespace="System.Data.SqlClient" %>
> <script runat="server">
> Sub Page_Load(sender As Object, e As EventArgs)
> Dim myConnection As SqlConnection
> Dim myCommand As SqlDataAdapter
> myConnection = New SqlConnection("server=local;user
> id=whocares;database=dbSeekersClientApp;Trusted_Co nnection=false")
> myCommand = New SqlDataAdapter("SELECT ID, username, password,
> firstname, surname, account_live FROM t_managers", myConnection)
> Dim ds As Dataset = new DataSet()
> myCommand.Fill(ds)
> MyRepeater.DataSource = ds
> MyRepeater.DataBind()
> End SUb
> </script>
> <html>
> <head>
> </head>
> <body>
> <form action="intro1.aspx" method="post" runat="server">
> <ASP:Repeater id="MyRepeater" runat="server">
> <HeaderTemplate>
> <table width="100%" style="font: 8pt verdana">
> <tr style="background-color:DFA894">
> <th>
> User ID
> </th>
> <th>
> Surname
> </th>
> <th>
> Firstname
> </th>
> <th>
> Username
> </th>
> <th>
> Password
> </th>
> <th>
> Access
> </th>
> </tr>
> </HeaderTemplate>
> <ItemTemplate>
> <tr style="background-color:FFECD8">
> <td>
> <%# DataBinder.Eval(Container.DataItem, "ID") %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem, "surname")
> %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem,
> "firstname") %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem,
> "username") %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem,
> "password") %>
> </td>
> <td>
> >>>>> Problem code
> <asp:DropDownList id="dList1" width=100 runat="server">
> <option
> value=<%#DataBinder.Eval(Container.DataItem, "account_live")%>>
> <%# DataBinder.Eval(Container.DataItem, "account_live") %>
> </option>
> >>>> Problem code ends
> </asp:DropDownList>
> </td>
> </tr>
> </ItemTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
> </ASP:Repeater>
> </form>
> </body>
> </html>
>
> Any pointers?
Friday, March 16, 2012
Newbie needing help with a simple ASP.NET <table> problem...!
that's got me tearing my hair out! I'm wanting to have a repeater that
adds some rows to a table as below:
<asp:Repeater ID="repeater1" runat="server">
<HeaderTemplate>
<table id="table1" runat="server">
<tr>{header code goes here}</tr>
</HeaderTemplate>
<ItemTemplate>
<tr><td>
<asp:DropDownList ID="ddl1" runat="server">{drop-down list code goes
here}</asp:DropDownList>
</td></tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
1. However, because of the 'runat="server"' in the table tag, this
throws an 'Unexpected end of file looking for </HeaderTemplatetag'
error.
2. Removing the 'runat="server"' means that the code DOES compile -
however it seems to have the effect that whenever I try to do anything
with my drop-down list in the page-behind vb gives me a 'Object
reference not set to an instance of an object' error (not a problem
with the way I'm coding because the same line works fine in the vb if
the drop-down list is placed OUTSIDE of the table).
3. Also, the only other way I can think of to do this, to use an
<asp:tableinstead (which was actually my preferred choice if I could
have got it working) gives a 'Server elements cannot span templates'
error.
Aaargghhh! There MUST be some way of having a repeater in a table as
above, AND allow server controls (that are actually useable) within
it. Can anyone help, as my head is sore from banging it against the
wall so much!
Many, many thanks indeed.Are you sure it's an error? I use this technique all the time, it does flag
up as a *warning*, but just ignore it.
<mj.redfox.mj@dotnet.itags.org.gmail.comwrote in message
news:1172763165.984403.148440@dotnet.itags.org.z35g2000cwz.googlegr oups.com...
Quote:
Originally Posted by
Hello, I'm hoping someone can help me out with a very basic problem
that's got me tearing my hair out! I'm wanting to have a repeater that
adds some rows to a table as below:
>
>
<asp:Repeater ID="repeater1" runat="server">
>
<HeaderTemplate>
<table id="table1" runat="server">
<tr>{header code goes here}</tr>
</HeaderTemplate>
>
<ItemTemplate>
<tr><td>
<asp:DropDownList ID="ddl1" runat="server">{drop-down list code goes
here}</asp:DropDownList>
</td></tr>
</ItemTemplate>
>
<FooterTemplate>
</table>
</FooterTemplate>
>
>
1. However, because of the 'runat="server"' in the table tag, this
throws an 'Unexpected end of file looking for </HeaderTemplatetag'
error.
>
2. Removing the 'runat="server"' means that the code DOES compile -
however it seems to have the effect that whenever I try to do anything
with my drop-down list in the page-behind vb gives me a 'Object
reference not set to an instance of an object' error (not a problem
with the way I'm coding because the same line works fine in the vb if
the drop-down list is placed OUTSIDE of the table).
>
3. Also, the only other way I can think of to do this, to use an
<asp:tableinstead (which was actually my preferred choice if I could
have got it working) gives a 'Server elements cannot span templates'
error.
>
>
Aaargghhh! There MUST be some way of having a repeater in a table as
above, AND allow server controls (that are actually useable) within
it. Can anyone help, as my head is sore from banging it against the
wall so much!
>
Many, many thanks indeed.
>
Hi Aidy,
Thanks for replying. Can I just ask which of the three techniques you
use...
1. <asp:table>
2. <table>
or
3. <table runat = "server">?
On 1 Mar, 15:54, "Aidy" <a...@dotnet.itags.org.noemail.xxxa.comwrote:
Quote:
Originally Posted by
Are you sure it's an error? I use this technique all the time, it does flag
up as a *warning*, but just ignore it.
>
<mj.redfox...@dotnet.itags.org.gmail.comwrote in message
>
news:1172763165.984403.148440@dotnet.itags.org.z35g2000cwz.googlegr oups.com...
>
>
>
Quote:
Originally Posted by
Hello, I'm hoping someone can help me out with a very basic problem
that's got me tearing my hair out! I'm wanting to have a repeater that
adds some rows to a table as below:
>
Quote:
Originally Posted by
<asp:Repeater ID="repeater1" runat="server">
>
Quote:
Originally Posted by
<HeaderTemplate>
<table id="table1" runat="server">
<tr>{header code goes here}</tr>
</HeaderTemplate>
>
Quote:
Originally Posted by
<ItemTemplate>
<tr><td>
<asp:DropDownList ID="ddl1" runat="server">{drop-down list code goes
here}</asp:DropDownList>
</td></tr>
</ItemTemplate>
>
Quote:
Originally Posted by
<FooterTemplate>
</table>
</FooterTemplate>
>
Quote:
Originally Posted by
1. However, because of the 'runat="server"' in the table tag, this
throws an 'Unexpected end of file looking for </HeaderTemplatetag'
error.
>
Quote:
Originally Posted by
2. Removing the 'runat="server"' means that the code DOES compile -
however it seems to have the effect that whenever I try to do anything
with my drop-down list in the page-behind vb gives me a 'Object
reference not set to an instance of an object' error (not a problem
with the way I'm coding because the same line works fine in the vb if
the drop-down list is placed OUTSIDE of the table).
>
Quote:
Originally Posted by
3. Also, the only other way I can think of to do this, to use an
<asp:tableinstead (which was actually my preferred choice if I could
have got it working) gives a 'Server elements cannot span templates'
error.
>
Quote:
Originally Posted by
Aaargghhh! There MUST be some way of having a repeater in a table as
above, AND allow server controls (that are actually useable) within
it. Can anyone help, as my head is sore from banging it against the
wall so much!
>
Quote:
Originally Posted by
Many, many thanks indeed.- Hide quoted text -
>
- Show quoted text -
I use the repeater;
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<mj.redfox.mj@dotnet.itags.org.gmail.comwrote in message
news:1172764802.765456.68170@dotnet.itags.org.h3g2000cwc.googlegrou ps.com...
Quote:
Originally Posted by
Hi Aidy,
>
Thanks for replying. Can I just ask which of the three techniques you
use...
1. <asp:table>
2. <table>
or
3. <table runat = "server">?
>
On 1 Mar, 15:54, "Aidy" <a...@dotnet.itags.org.noemail.xxxa.comwrote:
Quote:
Originally Posted by
>Are you sure it's an error? I use this technique all the time, it does
>flag
>up as a *warning*, but just ignore it.
>>
><mj.redfox...@dotnet.itags.org.gmail.comwrote in message
>>
>news:1172763165.984403.148440@dotnet.itags.org.z35g2000cwz.googlegr oups.com...
>>
>>
>>
Quote:
Originally Posted by
Hello, I'm hoping someone can help me out with a very basic problem
that's got me tearing my hair out! I'm wanting to have a repeater that
adds some rows to a table as below:
>>
Quote:
Originally Posted by
<asp:Repeater ID="repeater1" runat="server">
>>
Quote:
Originally Posted by
<HeaderTemplate>
<table id="table1" runat="server">
<tr>{header code goes here}</tr>
</HeaderTemplate>
>>
Quote:
Originally Posted by
<ItemTemplate>
<tr><td>
<asp:DropDownList ID="ddl1" runat="server">{drop-down list code goes
here}</asp:DropDownList>
</td></tr>
</ItemTemplate>
>>
Quote:
Originally Posted by
<FooterTemplate>
</table>
</FooterTemplate>
>>
Quote:
Originally Posted by
1. However, because of the 'runat="server"' in the table tag, this
throws an 'Unexpected end of file looking for </HeaderTemplatetag'
error.
>>
Quote:
Originally Posted by
2. Removing the 'runat="server"' means that the code DOES compile -
however it seems to have the effect that whenever I try to do anything
with my drop-down list in the page-behind vb gives me a 'Object
reference not set to an instance of an object' error (not a problem
with the way I'm coding because the same line works fine in the vb if
the drop-down list is placed OUTSIDE of the table).
>>
Quote:
Originally Posted by
3. Also, the only other way I can think of to do this, to use an
<asp:tableinstead (which was actually my preferred choice if I could
have got it working) gives a 'Server elements cannot span templates'
error.
>>
Quote:
Originally Posted by
Aaargghhh! There MUST be some way of having a repeater in a table as
above, AND allow server controls (that are actually useable) within
it. Can anyone help, as my head is sore from banging it against the
wall so much!
>>
Quote:
Originally Posted by
Many, many thanks indeed.- Hide quoted text -
>>
>- Show quoted text -
>
>
Could it be that the problem is that the header template opens outside
the <tabletag and ends inside it? Could you move the opening table
tag below the header template?
On Mar 1, 11:07 am, "Aidy" <a...@dotnet.itags.org.noemail.xxxa.comwrote:
Quote:
Originally Posted by
I use the repeater;
>
<HeaderTemplate>
<table>
</HeaderTemplate>
>
<ItemTemplate>
<tr>
>
</tr>
</ItemTemplate>
>
<FooterTemplate>
</table>
</FooterTemplate>
>
<mj.redfox...@dotnet.itags.org.gmail.comwrote in message
>
news:1172764802.765456.68170@dotnet.itags.org.h3g2000cwc.googlegrou ps.com...
>
>
>
Quote:
Originally Posted by
Hi Aidy,
>
Quote:
Originally Posted by
Thanks for replying. Can I just ask which of the three techniques you
use...
1. <asp:table>
2. <table>
or
3. <table runat = "server">?
>
Quote:
Originally Posted by
On 1 Mar, 15:54, "Aidy" <a...@dotnet.itags.org.noemail.xxxa.comwrote:
Quote:
Originally Posted by
Are you sure it's an error? I use this technique all the time, it does
flag
up as a *warning*, but just ignore it.
>
Quote:
Originally Posted by
Quote:
Originally Posted by
<mj.redfox...@dotnet.itags.org.gmail.comwrote in message
>
Quote:
Originally Posted by
Quote:
Originally Posted by
>news:1172763165.984403.148440@dotnet.itags.org.z35g2000cwz.googlegr oups.com...
>
Quote:
Originally Posted by
Quote:
Originally Posted by
Hello, I'm hoping someone can help me out with a very basic problem
that's got me tearing my hair out! I'm wanting to have a repeater that
adds some rows to a table as below:
>
Quote:
Originally Posted by
Quote:
Originally Posted by
<asp:Repeater ID="repeater1" runat="server">
>
Quote:
Originally Posted by
Quote:
Originally Posted by
<HeaderTemplate>
<table id="table1" runat="server">
<tr>{header code goes here}</tr>
</HeaderTemplate>
>
Quote:
Originally Posted by
Quote:
Originally Posted by
<ItemTemplate>
<tr><td>
<asp:DropDownList ID="ddl1" runat="server">{drop-down list code goes
here}</asp:DropDownList>
</td></tr>
</ItemTemplate>
>
Quote:
Originally Posted by
Quote:
Originally Posted by
<FooterTemplate>
</table>
</FooterTemplate>
>
Quote:
Originally Posted by
Quote:
Originally Posted by
1. However, because of the 'runat="server"' in the table tag, this
throws an 'Unexpected end of file looking for </HeaderTemplatetag'
error.
>
Quote:
Originally Posted by
Quote:
Originally Posted by
2. Removing the 'runat="server"' means that the code DOES compile -
however it seems to have the effect that whenever I try to do anything
with my drop-down list in the page-behind vb gives me a 'Object
reference not set to an instance of an object' error (not a problem
with the way I'm coding because the same line works fine in the vb if
the drop-down list is placed OUTSIDE of the table).
>
Quote:
Originally Posted by
Quote:
Originally Posted by
3. Also, the only other way I can think of to do this, to use an
<asp:tableinstead (which was actually my preferred choice if I could
have got it working) gives a 'Server elements cannot span templates'
error.
>
Quote:
Originally Posted by
Quote:
Originally Posted by
Aaargghhh! There MUST be some way of having a repeater in a table as
above, AND allow server controls (that are actually useable) within
it. Can anyone help, as my head is sore from banging it against the
wall so much!
>
Quote:
Originally Posted by
Quote:
Originally Posted by
Many, many thanks indeed.- Hide quoted text -
>
Quote:
Originally Posted by
Quote:
Originally Posted by
- Show quoted text -- Hide quoted text -
>
- Show quoted text -
Newbie needing help with a simple ASP.NET <table> problem...!
that's got me tearing my hair out! I'm wanting to have a repeater that
adds some rows to a table as below:
<asp:Repeater ID="repeater1" runat="server">
<HeaderTemplate>
<table id="table1" runat="server">
<tr>{header code goes here}</tr>
</HeaderTemplate>
<ItemTemplate>
<tr><td>
<asp:DropDownList ID="ddl1" runat="server">{drop-down list code goes
here}</asp:DropDownList>
</td></tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
1. However, because of the 'runat="server"' in the table tag, this
throws an 'Unexpected end of file looking for </HeaderTemplate> tag'
error.
2. Removing the 'runat="server"' means that the code DOES compile -
however it seems to have the effect that whenever I try to do anything
with my drop-down list in the page-behind vb gives me a 'Object
reference not set to an instance of an object' error (not a problem
with the way I'm coding because the same line works fine in the vb if
the drop-down list is placed OUTSIDE of the table).
3. Also, the only other way I can think of to do this, to use an
<asp:table> instead (which was actually my preferred choice if I could
have got it working) gives a 'Server elements cannot span templates'
error.
Aaargghhh! There MUST be some way of having a repeater in a table as
above, AND allow server controls (that are actually useable) within
it. Can anyone help, as my head is sore from banging it against the
wall so much!
Many, many thanks indeed.Are you sure it's an error? I use this technique all the time, it does flag
up as a *warning*, but just ignore it.
<mj.redfox.mj@.gmail.com> wrote in message
news:1172763165.984403.148440@.z35g2000cwz.googlegroups.com...
> Hello, I'm hoping someone can help me out with a very basic problem
> that's got me tearing my hair out! I'm wanting to have a repeater that
> adds some rows to a table as below:
>
> <asp:Repeater ID="repeater1" runat="server">
> <HeaderTemplate>
> <table id="table1" runat="server">
> <tr>{header code goes here}</tr>
> </HeaderTemplate>
> <ItemTemplate>
> <tr><td>
> <asp:DropDownList ID="ddl1" runat="server">{drop-down list code goes
> here}</asp:DropDownList>
> </td></tr>
> </ItemTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
>
> 1. However, because of the 'runat="server"' in the table tag, this
> throws an 'Unexpected end of file looking for </HeaderTemplate> tag'
> error.
> 2. Removing the 'runat="server"' means that the code DOES compile -
> however it seems to have the effect that whenever I try to do anything
> with my drop-down list in the page-behind vb gives me a 'Object
> reference not set to an instance of an object' error (not a problem
> with the way I'm coding because the same line works fine in the vb if
> the drop-down list is placed OUTSIDE of the table).
> 3. Also, the only other way I can think of to do this, to use an
> <asp:table> instead (which was actually my preferred choice if I could
> have got it working) gives a 'Server elements cannot span templates'
> error.
>
> Aaargghhh! There MUST be some way of having a repeater in a table as
> above, AND allow server controls (that are actually useable) within
> it. Can anyone help, as my head is sore from banging it against the
> wall so much!
> Many, many thanks indeed.
>
Hi Aidy,
Thanks for replying. Can I just ask which of the three techniques you
use...
1. <asp:table>
2. <table>
or
3. <table runat = "server">?
On 1 Mar, 15:54, "Aidy" <a...@.noemail.xxxa.com> wrote:
> Are you sure it's an error? I use this technique all the time, it does fl
ag
> up as a *warning*, but just ignore it.
> <mj.redfox...@.gmail.com> wrote in message
> news:1172763165.984403.148440@.z35g2000cwz.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
I use the repeater;
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<mj.redfox.mj@.gmail.com> wrote in message
news:1172764802.765456.68170@.h3g2000cwc.googlegroups.com...
> Hi Aidy,
> Thanks for replying. Can I just ask which of the three techniques you
> use...
> 1. <asp:table>
> 2. <table>
> or
> 3. <table runat = "server">?
> On 1 Mar, 15:54, "Aidy" <a...@.noemail.xxxa.com> wrote:
>
Could it be that the problem is that the header template opens outside
the <table> tag and ends inside it? Could you move the opening table
tag below the header template?
On Mar 1, 11:07 am, "Aidy" <a...@.noemail.xxxa.com> wrote:
> I use the repeater;
> <HeaderTemplate>
> <table>
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> </tr>
> </ItemTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
> <mj.redfox...@.gmail.com> wrote in message
> news:1172764802.765456.68170@.h3g2000cwc.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -