|
-
Mar 26th, 2007, 02:36 PM
#1
[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:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txtDate As TextBox = DetailsView1.FindControl("TextBox6")
txtDate.Text = System.DateTime.Now
Dim txtPostedBy As TextBox = DetailsView1.FindControl("TextBox2")
txtPostedBy.Text = Membership.GetUser.UserName.ToString
Dim txtMod As TextBox = DetailsView1.FindControl("TextBox3")
txtMod.Text = System.DateTime.Now
Dim txtModBy As TextBox = DetailsView1.FindControl("TextBox1")
txtModBy.Text = Membership.GetUser.UserName.ToString
DetailsView1.InsertItem(False)
Response.Redirect("~/msgboard.aspx")
End Sub
-
Mar 26th, 2007, 02:51 PM
#2
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.
-
Mar 26th, 2007, 02:52 PM
#3
Fanatic Member
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.
-
Mar 26th, 2007, 02:55 PM
#4
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|