I am using formview to pull the data from DB for user to view and edit. I would like to be able to insert system date and username into the DB if user edits the row. I have placed an insert statement into "Update" section of the datasource so that all
fields are pre generated when user clicks edit and when submitted it creates a new row in the DB so we can record change history. so I would like to generate the username and updated date fields with system date and system username. any help is appreciated.
thanks
Private Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
Select Case FormView1.CurrentMode
Case FormViewMode.Edit
Protected Sub FormView1_ModeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Handles FormView1.ModeChanged
If FormView1.DefaultMode = FormViewMode.Insert Then
Dim tb As TextBox = CType(FormView1.FindControl("UsernameTextBox"), TextBox)
tb.Text = User.Identity.Name
End If
End Sub
I cant get it to work. not sure why. here is my code. It just wont generate the username in the text box so when I enter update it wont write it to SQL
Protected Sub FormView1_DataBound(sender As Object, e As EventArgs)
If FormView1.CurrentMode = FormViewMode.Edit Then
Dim tb As TextBox = DirectCast(FormView1.FindControl
CaptainAmeri...
None
0 Points
15 Posts
Insert SystemUsername into formview text box.
Dec 28, 2012 05:08 PM|LINK
Hello,
I am using formview to pull the data from DB for user to view and edit. I would like to be able to insert system date and username into the DB if user edits the row. I have placed an insert statement into "Update" section of the datasource so that all fields are pre generated when user clicks edit and when submitted it creates a new row in the DB so we can record change history. so I would like to generate the username and updated date fields with system date and system username. any help is appreciated. thanks
oned_gk
All-Star
30991 Points
6344 Posts
Re: Insert SystemUsername into formview text box.
Dec 28, 2012 05:37 PM|LINK
CaptainAmeri...
None
0 Points
15 Posts
Re: Insert SystemUsername into formview text box.
Dec 28, 2012 05:42 PM|LINK
How do I bind User.Identit.Name to a text box in the formview? I can do it if the textbox is outside og the formview.
oned_gk
All-Star
30991 Points
6344 Posts
Re: Insert SystemUsername into formview text box.
Dec 28, 2012 05:52 PM|LINK
CaptainAmeri...
None
0 Points
15 Posts
Re: Insert SystemUsername into formview text box.
Dec 28, 2012 06:14 PM|LINK
didnt work.
This is what I have so far.
Private Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
Select Case FormView1.CurrentMode
Case FormViewMode.Edit
Textbox textbox2 = (Textbox)Formview1.findcontrol("textbox2") textbox2.Text= User.Identity.Name
End Select
End Sub
CaptainAmeri...
None
0 Points
15 Posts
Re: Insert SystemUsername into formview text box.
Dec 28, 2012 06:29 PM|LINK
I also tried below and text box is still blank.
<asp:TextBox ID="UsernameTextBox" runat="server" Text='<%# User.Identity.Name %>' />
oned_gk
All-Star
30991 Points
6344 Posts
Re: Insert SystemUsername into formview text box.
Dec 29, 2012 02:22 AM|LINK
<asp:TextBox ID="UsernameTextBox" runat="server" Text='<%# Bind("Username") %>' />In modechanged event
Protected Sub FormView1_ModeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.ModeChanged If FormView1.DefaultMode = FormViewMode.Insert Then Dim tb As TextBox = CType(FormView1.FindControl("UsernameTextBox"), TextBox) tb.Text = User.Identity.Name End If End SubCaptainAmeri...
None
0 Points
15 Posts
Re: Insert SystemUsername into formview text box.
Jan 02, 2013 02:26 PM|LINK
I cant get it to work. not sure why. here is my code. It just wont generate the username in the text box so when I enter update it wont write it to SQL
Protected Sub FormView1_DataBound(sender As Object, e As EventArgs) If FormView1.CurrentMode = FormViewMode.Edit Then Dim tb As TextBox = DirectCast(FormView1.FindControl("UsernameTextBox"), TextBox)tb.Text = User.Identity.Name End If End Sub<asp:TextBox ID="UsernameTextBox" runat="server" Text='<%# Bind("Username") %>' /> <br />