Results 1 to 4 of 4

Thread: [RESOLVED] [2005] DetailsView programmatically added information not working correctly

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Resolved [RESOLVED] [2005] DetailsView programmatically added information not working correctly

    I need a message board for one of my current projects. The user should only see text boxes for the message title and the body. However, the table that the user is writing to has seven properties. The ID is being added just fine, but the other four are being weird.

    When I set the field visible properties to True and leave the fields blank, the code adds everything just fine. But I want them False... and when I do that, they don't set anything. Any solutions?

    Here's the code that adds the information.
    vb Code:
    1. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim txtDate As TextBox = DetailsView1.FindControl("TextBox6")
    4.         txtDate.Text = System.DateTime.Now
    5.  
    6.         Dim txtPostedBy As TextBox = DetailsView1.FindControl("TextBox2")
    7.         txtPostedBy.Text = Membership.GetUser.UserName.ToString
    8.  
    9.         Dim txtMod As TextBox = DetailsView1.FindControl("TextBox3")
    10.         txtMod.Text = System.DateTime.Now
    11.  
    12.         Dim txtModBy As TextBox = DetailsView1.FindControl("TextBox1")
    13.         txtModBy.Text = Membership.GetUser.UserName.ToString
    14.  
    15.         DetailsView1.InsertItem(False)
    16.         Response.Redirect("~/msgboard.aspx")
    17.  
    18.     End Sub

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] DetailsView programmatically added information not working correctly

    If you put your code in a try/catch block, you would probably find something... My guess is that your detailsview was not in insert mode when the code ran and it triggered an HttpException. Try to change the mode to insert first and see if it works.

  3. #3
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Re: [2005] DetailsView programmatically added information not working correctly

    I hope I did understand your problem, I'll just give a try.

    Wrap those codes w/ the "If" statement and use the textbox's visible property for the condition whether to set the value or not.

  4. #4

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: [2005] DetailsView programmatically added information not working correctly

    Wasn't the text boxes... it was the field property itself. This line was the fix (repeated for each field):

    vb Code:
    1. DetailsView1.Fields.Item(1).Visible = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width