Hi, I can't seem to get my repeater to work. It's my first time trying it out, the code I've been reading doesn't seem too complicated, but I am doing something wrong, and I'm hoping someone can spot the mistake. Here is my .ASPX form. It's just in trying to get something to work phase 1:<BR><BR><form id="Form1" method="post" runat="server"><BR> <asp:Repeater><BR> <ItemTemplate><BR> <%#DataBinder.Eval(Container.DataItem, "FullName")%> <BR> </ItemTemplate><BR> </asp:Repeater><BR> <asp:TextBox id="txtStaffName" style="Z-INDEX: 101; LEFT: 18px; POSITION: absolute; TOP: 218px" runat="server" Width="122px" Height="28px"></asp:TextBox><BR> <asp
ropDownList id="cboRoles" style="Z-INDEX: 102; LEFT: 26px; POSITION: absolute; TOP: 273px" runat="server" Width="109px" Height="21px"></asp
ropDownList><BR> </form><BR><BR><BR>And here is my .aspx.vb code:<BR><BR>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here<BR> MyConnection = New SqlConnection("Password=specsapp;Persist Security Info=True;User ID=SpecsApp;Initial Catalog=Specifications;Data Source=TMCS303")<BR> StaffNames()<BR> End Sub<BR><BR> Private Sub StaffNames()<BR> Dim DSStaff As DataSet<BR> Dim sdaStaff As SqlCommand<BR> Dim strStaff As String<BR><BR> strStaff = "select iStaffID, vFirstName+' '+vLastName as FullName from Staff order by vLastName"<BR><BR> MyConnection.Open()<BR> ' Creating the Dataset for Project Name & Code<BR> sdaStaff = New SqlCommand(strStaff, MyConnection)<BR> cboRoles.DataSource = sdaStaff.ExecuteReader()<BR> cboRoles.DataTextField = "FullName"<BR> cboRoles.DataValueField = "iStaffID"<BR> cboRoles.DataBind()<BR> MyConnection.Close()<BR><BR> End Sub<BR><BR>The compilation error that I am getting
is:<BR> BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.<BR><BR><BR>If anyone know, your help would be soooo appreciated. Thanks!<BR>change your repeater tag to this<BR><BR><asp:repeater runat="Server" id="cboRoles">A word of caution about some of your code here<BR><BR><asp:TextBox id="txtStaffName" style="Z-INDEX: 101; LEFT: 18px; POSITION: absolute; TOP: 218px" runat="server" Width="122px" Height="28px"></asp:TextBox><BR><BR>I don't recommend you have a style tag that uses z-indexing. You are dynamically adjusting where your text boxes are using CSS. The big problem is cross browser compatibility. Mozilla and IE are notorious at having different placements with z-indexing and left and right adjustments. Go to mozillazine.org and download mozilla and test it to make sure they line the same way in both browsers.That got rid of that stupid error, thanks!!!<BR><BR>Butm my drop down list is bound, but the repeater just displays "databound" 5 times since there are five entries in Staff Names.<BR>How do I get the drop down list to repeat 5 times inside of the repeater in reference to the code I posted the first time ?<BR>Any ideas?Yeah, that is not going to stay there. Once I can get them to dynanically display I want to take it out. But I wasn't sure where to create it besides the aspx page. And the datagrid format made those
<BR>Your SQL statement looks funny to me. Are you sure it is pulling your data from the DB?<BR><BR>I would try and change this line<BR>strStaff = "select iStaffID, vFirstName+' '+vLastName as FullName from Staff order by vLastName" <BR><BR>into this line<BR>strStaff = "select iStaffID, vFirstName,vLastName from Staff order by vLastName" <BR><BR>Ooops I noticed a problem with my last post..Do you have a FULLNAME filed in your DB or is this some sort of join or alias? Try just this<BR><BR>strStaff = "select * from Staff order by vLastName"<BR><BR>If that works I would then change it to <BR><BR>strStaff = "select istaffID,vfirstname, vlastname, vfullname from Staff order by vLastName"<BR><BR>You never want to return an entire recordset if you only want just a few fields.<BR>Yeah, no my SQL statement is fine. I can populate my drop down list with it. Just cant get the list to show up in the repeater code. Am I maybe missing a repeater function or something???<BR><BR>Yeah, my sql statement is making a FullName alias using the first name and last name fields and then I am populating the drop down list with FullName.**** I'm so **** blind! Your dropdownlist is missing the runat="server" tag. Your textbox is missing it also. Add those lines and try it.Does your repeater object display its' contents? Your dropdownlist appears to be inheriting the same objects as your repeater control. Try removing your repeater object and see what happens to your dropdownlist.Ok, I do have runat=server is the asp button code, if that is what you mean.<BR>Ok, i think i'm confusing everything
<BR>How would I normally bing just one drop down list or one text box into a repeater and display all the contents?<BR>Where would I put the declarations of the asp buttons since I would want them to be dynamically built. Would I declare them iside of the repeater?Ok first of all what is repeater object for? by binding your data to a dropdownlist it will automatically populate it with data from your database.<BR><BR>If you want to use a textbox then you should use either a datalist or datagrid not a repeater. To make it simple I'm showing you some code i whipped up in 5 minutes. It displays a list of counties then gives me the countycode whenever I select a county from the dropdownlist.<BR><BR><script runat="server"><BR>sub page_load(sender as object,e as eventargs)<BR>dim myconnection as sqlconnection<BR>dim mycommand as sqlcommand<BR>dim Ssql as string<BR> Ssql = "Select county,countycode from counties_ga"<BR>myconnection = new sqlconnection("server=localhost;uid=sa;pwd=;database=ga filing.net")<BR>myconnection.open<BR><BR>mycommand = new sqlcommand(Ssql,myconnection)<BR>datafile.datasource = mycommand.executereader()<BR>datafile.datatextfield = "County"<BR>datafile.datavaluefield = "CountyCode"<BR>datafile.databind()<BR><BR>myconnection.close()<BR>end sub<BR><BR>sub load_item(sender as object,e as eventargs)<BR> response.write(datafile.selecteditem.value)<BR>end sub<BR><BR></script><BR><BR><form runat="server"><BR> <asp:dropdownlist id="datafile" runat="server" onselectedindexchanged="load_item" autopostback="true" /><BR></form><BR><BR>This is the simplest form of binding to a dropdownlist. If you also want to use a repeater on the same page then you will have to add this to your code to the form <BR><BR> <asp:repeater id="myrepeater" runat="server"><BR> <itemtemplate><BR> <%#container.dataitem("county")%><BR> </itemtemplate><BR> </asp:repeater><BR><BR>and add this code to your script right after the MYCONNECTION.CLOSE() tag<BR><BR>myconnection.open<BR>mycommand = new sqlcommand(ssql,myconnection)<BR> myrepeater.datasource = mycommand.executereader()<BR> myrepeater.databind()<BR>myconnection.close()<BR><BR><BR>Hope this helps...<BR>Yeah, thanks! I did all that. I don't know what I'm doing wrong.<BR>I just keep getting my text box and my drop down from the page and no repeater.<BR>Thanks for trying!




