locked
How do I add or remove databound fields from Form? RRS feed

  • Question

  • User206499579 posted

    Someone please give me a run down on how to add databound fields to Classifieds Online Kit.
    For instance; add fields: Color, Length, Manufacturer, Condition...
    I created database fields in "Ads" table and I'm stuck with PostAd.aspx page. Can't figure out how to pull in a field that would post back to database.
    I updated (InsertAd) Store Procedure, scripted field (Color) in PostAd.aspx. Tested, and the new field is not posting. What's missing?
    It has to be a better way.

     

    Update,

    Three days later and there’s no answer, which turned out to be one thought question, sorry boys for testing your limits.

     

    Saturday, July 12, 2008 5:23 AM

All replies

  • User730446648 posted

    It's bright and sunny here in Washington, so good luck getting any help from me on the weekend.

     

    I've gone through it many times, so take a look at this post.

    http://forums.asp.net/p/1099845/1669713.aspx#1669713

    To get answers faster try doing an advanced search, usually someone has already gone through the same issue.

    Good Luck

    Daniel

    Monday, July 14, 2008 11:37 AM
  • User206499579 posted

    I hear you <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on"><st1:City w:st="on">Daniel</st1:City>, <st1:State w:st="on">Washington</st1:State></st1:place> state should be nice this time of the year. Here in <st1:place w:st="on"><st1:City w:st="on">Stockholm</st1:City>, <st1:country-region w:st="on">Sweden</st1:country-region></st1:place> rains every day and it gets colder than I thought it would. I’m on a business trip and in the morning while the office in <st1:place w:st="on"><st1:State w:st="on">New York</st1:State></st1:place> is closed I entertain myself with programming Classified Ads. The kit is been offer to download for two years, if not longer and now I seem to have the time and purposes to make something of it. If works will serve local equestrian Swedes who seem to have a problem exchanging specialized products. I was pleasantly surprise when found out that the most desirable breed in Sweden is our American Quarter-horse, and everything else that goes with.

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    Back to adding a field – your advise was very helpful in pointing the flow. I checked and edited: tables, views, stored procedure. In App_Code I edited Ads.xsd, after that had some twelve error messages coming for BLL, Ads.vb.

    I fixed some, run Debug and I’m left with two error messages pointing to adType.

    What am I missing?

    Pages open as should but when I enter data to update that one field there is no post back and no error message either.

    Here is the debugging error message.

    <o:p> </o:p>C:\Documents and Settings\customer\My Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual Basic\VisualBasic\Classified Ads\PostAd.aspx.vb(53,0): error BC30455: Argument not specified for parameter 'adType' of 'Public Shared Sub RelistAd(adId As Integer, categoryId As Integer, title As String, color As String, description As String, url As String, price As Decimal, location As String, numDaysActive As Integer, adLevel As AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdLevel, adStatus As AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdStatus, adType As AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdType)'.<o:p></o:p>C:\Documents and Settings\customer\My Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual Basic\VisualBasic\Classified Ads\PostAd.aspx.vb(58,0): error BC30455: Argument not specified for parameter 'adType' of 'Public Shared Function InsertAd(memberId As Integer, categoryId As Integer, title As String, color As String, description As String, url As String, price As Decimal, location As String, numDaysActive As Integer, adLevel As AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdLevel, adStatus As AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdStatus, adType As AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdType) As Integer'.<o:p></o:p>Validation Complete<o:p></o:p>

    ========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

    Thank you,
    James

    Tuesday, July 15, 2008 9:44 AM
  • User206499579 posted

    Ok it's working – new field takes data and posts back to database, just as it should.

    I made it into a dropdown list and it’s working like a charm.

    It took a while to remember that asp.net splits the code of a page - had also to edit the code behind. PostAd.aspx and PostAd.aspx.vb go together but ...vb was the last to edit.

    I will have more questions on related topics but on this one I’m satisfied, case closed.

    Thank you Daniel, you were a great help.

     

    Regards,

    James

     

    The real solution though is further down on post 13.

    Editing the code beding - in postad.aspx.vb not needed.

    Tuesday, July 15, 2008 3:04 PM
  • User730446648 posted

    Glad to hear you got it.

    Just don't forget, now that you have had a decent update, make a dated backup.

    I can't tell you how many times I thought I had everything working right, and my new update caused an error elsewhere.

    So backup, backup, backup. . . .

     

    Tuesday, July 15, 2008 6:08 PM
  • User206499579 posted

    Question on “ShowAd.aspx”;

    After scripting-in, the field “Color” I get an error message – this one;

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>DataBinding: 'AdsDataComponent+AdsRow' does not contain a property with the name 'Color'.<o:p></o:p><o:p> </o:p>

    I know what it means, but where is that AdsDataComponent+AdsRow?

    Item details <o:p></o:p>

    Item # <o:p></o:p> <?xml:namespace prefix = asp /><asp:Label id=AdIdLabel __designer:dtid="1970324836974708" Text='<%# Eval("Id") %>' Runat="server"></asp:Label><o:p> </o:p>
    Color:<o:p></o:p> <asp:Label id=Zodiac __designer:dtid="1970324836974713" Text='<%# Eval("Location") %>' Runat="server"></asp:Label><o:p> </o:p>
    Location:<o:p></o:p> <asp:Label id=LocationLabel __designer:dtid="1970324836974718" Text='<%# Eval("Location") %>' Runat="server"></asp:Label><o:p> </o:p>
    Category:<o:p></o:p> <asp:Label id=CategoryNameLabel __designer:dtid="1970324836974723" Text='<%# Eval("CategoryName") %>' Runat="server"></asp:Label><o:p> </o:p>
    URL:<o:p></o:p> <asp:HyperLink id=URLLink __designer:dtid="1970324836974727" Runat="server" Target="_blank"></asp:HyperLink><o:p> </o:p>
    Posted by:<o:p></o:p> <asp:HyperLink id=PostByLink __designer:dtid="1970324836974731" Text='<%# Eval("MemberName") %>' Runat="server" NavigateUrl='<%# Eval("MemberName", "~/Search.aspx?member={0}") %>'></asp:HyperLink><o:p> </o:p>
    Date Entered:<o:p></o:p> <asp:Label id=DateAddedLabel __designer:dtid="1970324836974735" Text='<%# Eval("DateCreated", "{0:D}") %>' Runat="server"></asp:Label><o:p> </o:p>
    Expiration:<o:p></o:p> <asp:Label id=ExpirationLabel __designer:dtid="1970324836974739" Runat="server"></asp:Label><o:p> </o:p>
    Currently:<o:p></o:p> <asp:Label id=AdStatusLabel __designer:dtid="1970324836974743" Text='<%# OutputFormatting.AdTypeToString(Eval("AdType")) %>' Runat="server"></asp:Label><o:p> </o:p>
    Description:<o:p></o:p> <asp:Label id=DescriptionLabel __designer:dtid="1970324836974748" Text='<%# Eval("Description") %>' Runat="server"></asp:Label><o:p> </o:p>
    <o:p> </o:p></ITEMTEMPLATE>

    One other question – Should I post this question here or make a new post?

    I marked Resolved - new question might not get an answer from wizards.

    <o:p> </o:p>

    About backups - you wrote, backup 3 or 4 times, I took 5 J

    I went back few times but only to copy and paste App_Code. That worked out errors. However, after few rounds over few days, I went back all the way to first backup and that help. By then I had a better perception of error solving and produced a clear result.

     I realized I was overdoing with coding.

    For instance, PostAd.aspx doesn’t need any coding other than inserting the new field, and updating one Stored Procedure.

    Now the ViewAd.aspx is a little different, the data source is sorted through Business Logic Layer, BLL and once I figure how that works I should be done.

     

    Thursday, July 17, 2008 4:39 PM
  • User730446648 posted

    First question:

    DataBinding: 'AdsDataComponent+AdsRow' does not contain a property with the name 'Color'. 

    I know what it means, but where is that AdsDataComponent+AdsRow?

    If you look in App_Code/DAL/Ads.xsd (just double click it)

    It shows what you currently have in the tables, you either forgot or misspelled color.

    The fix sounds like it lies in Ads.xsd

     

    For the most part, make a new post when it's off topic.

    I'd say you are still on topic.

     

    And just a pointer but I did have to make small modifications to the code behind on postad.aspx.

    Don't forget to check the repost ad feature, if the ad expires and they want to renew, it should be seamless for them.

    Glad to hear you are getting it.

    Just remember one step at a time.

     

    Thursday, July 17, 2008 6:54 PM
  • User206499579 posted

    It sounds like you have it all figure out.

    Could you run a description about how you did the adding of one field to PostAd.aspx?

    Tables to stored procedures, to form and other steps in between and we might learn something – by the way, from the read count, five hundred people appear to be as interested as I am.

     

    Friday, July 18, 2008 2:41 PM
  • User730446648 posted

    I am a very busy guy, and I don't have the time to go over it again.

    See the link at the top, or go through the code page by page, I learned a lot doing it that way.

    All I did is pick a column that was already in there and copied the way it was done.

    Pretty simple.

    One pointer is on postad.aspx.vb at the bottom you see a section (LoadPreviousAd) this is the area that loads when the ad is being reposted. Try changing the price textbox to this:

    PriceTextBox.Text = String.Format("{0:f2}", ad.Price)

    Easy relisting.

    Are you stuck somewhere?

    What's the issue?

     

    Friday, July 18, 2008 10:11 PM
  • User206499579 posted

     

    Inserting new field, error message

     

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>

    Error        1              Too many arguments to 'Public Overridable Overloads Function InsertAd(MemberId As Integer, CategoryId As Integer, Title As String, Description As String, URL As String, Price As Decimal, Location As String, ExpirationDate As System.Nullable(Of Date), DateCreated As Date, DateApproved As System.Nullable(Of Date), NumViews As Integer, NumResponses As Integer, AdLevel As Integer, AdStatus As Integer, AdType As Integer) As System.Nullable(Of Integer)'.              C:\Documents and Settings\customer\My Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual Basic\VisualBasic\Classified Ads\App_Code\BLL\Ads.vb  Line 106

     

    It means that the page “InsertAd” accepts a number of fields already predefined.<o:p></o:p>So far it works only when replacing an existing field for a new one. The error comes from BLL\Ads.vb – Business Logic Layer. <o:p></o:p><o:p> </o:p>The form has 15 fields and unless that number is increased it won’t accept new fields. <o:p></o:p>Now, I’m not sure if the number of fields is a default or a preset by designer. <o:p></o:p>

    It could be either but knowing for sure will tell me what I have to work with - that’s my stuck point.

     

    <o:p> </o:p><o:p>Here is how I got there, step by step.<o:p></o:p><o:p> 
    </o:p>
    Starting with a fresh copy of Classified Ads;<o:p></o:p>I run the site – created admin account and a user account.
    </o:p>
    <o:p>Logged in as user and added few records – view, editing - pages work fine.
    By the way the admin account has to be added in VS designer, users have to be added on the page or else won’t work.<o:p></o:p>
    <o:p> 
    </o:p>
    What follows is the new staff..
    <o:p></o:p>
    1. Added the field “Color” in Ads Table.
    <o:p></o:p>
    2. Added the field “Color” to Stored Procedure “InsertAd”<o:p></o:p>Run the page to insert a new record and I expect to get an error asking for the new field, it does and that’s correct.
     Now here is the thing mentioned in previously posted arguments.
    The Ads.esd in DAL doesn’t have to be edited because gets its settings for Stored Procedures.
    Also in Stored Procedures added fields couldn’t be misspelled even on purpose, alterations won’t save unless they check against tables.
    Misspells however could occur on independent queries, but we don’t have that here – well, there are two queries in Views but that’s separate.
    <o:p></o:p>
    3. Debug - the error message comes up says that the field Color is not specified in BLL.
    <o:p></o:p>
    I script-in the field, and I should declare it but I don’t because I know the next error message is gone ask that.
    <o:p></o:p>
    4. Debug again and sure the error message says - field “Color” hasn’t been declared. <o:p></o:p>I script in the declaration.
    <o:p></o:p>
    5 Debug – now it shouldn’t find any error, but it does - that’s the error above
    .<o:p></o:p>
    The error means, one field too many.
    <o:p></o:p>
    Never run into that before but it is what it is, I’ll take it as it comes.
    <o:p></o:p>
    That’s what I’m trying to find out. The number of fields, is it a default or created limit set by designer?
    <o:p></o:p>
    With that out of the way there should be no more problems with adding fields. </o:p>
    <o:p>

     

    This is the field declaration<o:p></o:p><o:p> 
    </o:p>
    #Region "InsertingAds"
    Public Shared Function InsertAd(ByVal memberId As Integer, ByVal categoryId As Integer, _
    ByVal title As String, ByVal description As String, ByVal url As String, _
    ByVal price As Decimal, ByVal location As String, ByVal numDaysActive As Integer, _
    ByVal adLevel As AdLevel, ByVal adStatus As AdStatus, _
    ByVal adType As AdType, ByVal color As String) As Integer
    #
    #

    Here is the field<o:p></o:p><o:p> </o:p><o:p> 
    </o:p>
    Using db As New AdsDataAdapter()<o:p></o:p> 
    adId = CInt(db.InsertAd(memberId, categoryId, title, description, url, price, _<o:p></o:p>
     
    location, expirationDate, dateCreated, dateApproved, _
    numViews, numResponses, CInt(adLevel), CInt(adStatus), CInt(adType), Color))<o:p></o:p>

    </o:p> 

    <o:p></o:p> </o:p>
    Saturday, July 19, 2008 4:12 AM
  • User206499579 posted

     

    Today I had a go at Classified Ads in #C.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    PostAd.aspx works until a new field is added.

    Again the error comes from Ads.cs in BLL.

    However, #C is more informative and says 16 arguments.<o:p></o:p>

    Is there a way to get past that limit?

    Here's the error message from #C<o:p> 
    </o:p>
     Error       1              No overload for method 'InsertAd' takes '16' arguments<o:p></o:p>                <o:p></o:p><o:p> 
    Regards
    </o:p>
    <o:p>James</o:p>

     

    Saturday, July 19, 2008 2:42 PM
  • User730446648 posted

    You said

    The Ads.esd in DAL doesn’t have to be edited because gets its settings for Stored Procedures.

    Yes it does.

     

    I don't know who told you it doesn't but does, and if you didn't, it would cause that type of error.

    enter your new column "color" into the DAL table, save, right click on the background, and choose "view code"

    It does use the stored procedures, but it's basically the middleman between them.

     

    Note: there is two sections for Insert Ads.

    And make sure you use the same order all the time.

    For example, you entered color after adtype in Ads.vb, you need to keep that order in Ads.xsd code aswell.

    Then it will work.

     

    By the way, I'm going on vacation for a week and a half, starting tomorrow morning.

    So I may not be able to respond depending on the area at Yellowstone.

    Good Luck.

     

    Saturday, July 19, 2008 9:23 PM
  • User206499579 posted
    Adding a new field to form is working and here is the fix for that puzzling error that bugged me for days. I could have hurt someone by throwing my vaio out the window. You haven’t seen that before, well come to <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on"><st1:State w:st="on">New York</st1:State></st1:place> and you’ll meet all kinds of comedians J
    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>Back to errors, bugs and fixes;
    Public Overridable Overloads Function - in visual basic
    <o:p></o:p>
    Error: No overload for method "field” takes 'x' arguments - in C sharp
    <o:p></o:p>
    All it takes is open and save the DataSet feeding the form and that’s the fix.
    <o:p></o:p>
    It’s that simple.
    <o:p></o:p>
    In “Classified Ads”, dataset to form PostAd.aspx is InsertAd, in DAL folder. When you right click and select Configure all looks ok because it pulls the field from Stored Procedure which was correctly updated AND that makes it confusign in figuring out the problem. I checked that dataset a thousand times and every time I clicked Cancel, and that wasn’t good. <o:p></o:p>Correctly, click ‘Next’ and leave the selection as is – “A Single Value” selected, ‘Next’ leave functions’ name as is “IsertAd”. Go Next and Finish - that’s it. Next time you run the form or debug everything will work just fine.
    <o:p></o:p>
    Another thing;<o:p></o:p>Since so many people read this thread on inserting a field on Classified Ads – so far over two thousand readers (July 21 08’) – here is a valid response from my own experience (answering my own question).
    <o:p></o:p>
    Add the new field in table Ads.
    <o:p></o:p>
    Update Store Procedure 'InsertAd'.
    <o:p></o:p>
    Open page PostAd.aspx in Design view.
    <o:p></o:p>
    Click and open “Wizard Task”(in template, top, right). For ‘Step’ select “Enter Ad Details”.
    <o:p></o:p>
    Pull from Tolbox a TextBox or a DropDownList.
    <o:p></o:p>
    Now you have to bind the field to the dataset and here is how;
    <o:p></o:p>
    Same page, Click ‘Source’ and find the script for field you just pulled.
    <o:p></o:p>
    Here's a sample script of the raw drop-down-list, reads like this;
    <o:p></o:p>
    <asp:DropDownList
    ID="DropDownList1" runat="server"><o:p></o:p>
    </asp:DropDownList>
    <o:p></o:p>
    When done editing, the new script would read something like this;
    <o:p></o:p>
    <asp:DropDownList Text='<%# Bind("Color") %>' ID="ColorTextBox" runat="server" ToolTip="please select color">
    <o:p></o:p>
    <asp:ListItem Selected="True">Green</asp:ListItem>
    <o:p></o:p>
    <asp:ListItem>Orange</asp:ListItem>
    <o:p></o:p>
    <asp:ListItem>Red</asp:ListItem>
    <o:p></o:p>
    <asp:ListItem>Blue</asp:ListItem>
    <o:p></o:p>
    </asp:DropDownList>
    <o:p></o:p>
    The most important is the binding part <%# Bind(“field”) %>.
    <o:p></o:p>
    Last step; remember to run and save the dataset ‘InsertAd’ in DAL folder.
    That’s it, you have a new field posting back to the database.
    <o:p></o:p>
    Same principle will work for every other page either in Visual Basic or C Sharp.

    Not very complicated, ain’t it? Only cost me couple of days!
    Regards,

    James

    Update,- a day later
    <o:p></o:p>
    For pulling new field/fields to ShowAd.aspx page.
    <o:p></o:p>
    It was tricky but it works now and here is the twist.
    <o:p></o:p>
    The data-source for the page is in DAL, Ads.xsd and data adapter, GetAdByID(@Id).
    <o:p></o:p>
    Again, the new data won’t show unless this structure is resaved, but here is the problem;
    <o:p></o:p>
    It won’t save because both methods are checked (Fill and Return) and have the same name.
    <o:p></o:p>
    To get around that uncheck “Fill a Data Table” and Save.
    Step two, come back and uncheck “Return a Data Table” and Save.
    <o:p></o:p>
    You’ll notice that those two methods (Fill and Return) by default are always checked.
    <o:p></o:p>
    With that out of the way, page ShowAd.aspx pulls data.<o:p></o:p>

     

    Monday, July 21, 2008 10:19 AM