metropia
asked on
how to put the current logged user on databound field
I have a details view with all databound fields
there is one field named ModifiedBy that I want to assign the current logged user to
I am trying to do it this way in the code behind:
but I get a:
System.NullReferenceExcept ion: Object reference not set to an instance of an object
on line
CType(Me.dvRecipeItem.Rows (0).FindCo ntrol("Mod ifiedBy"), TextBox).Text = strModifiedBy
Would anyone be able to offer some help on what is my problem?
thank you
there is one field named ModifiedBy that I want to assign the current logged user to
<asp:BoundField DataField="ModifiedBy" HeaderText="Modified By" SortExpression="ModifiedBy" ApplyFormatInEditMode="True" ReadOnly="true" />
I am trying to do it this way in the code behind:
Private Sub dvRecipeItem_DataBound(sender As Object, e As EventArgs) Handles dvRecipeItem.DataBound
Dim strModifiedBy As String = System.Web.Security.Membership.GetUser.UserName.Trim
CType(Me.dvRecipeItem.Rows(0).FindControl("ModifiedBy"), TextBox).Text = strModifiedBy
End Sub
but I get a:
System.NullReferenceExcept
on line
CType(Me.dvRecipeItem.Rows
Would anyone be able to offer some help on what is my problem?
thank you
ASKER
here is the html:
the aspx (right now the value comes from the entity data source
Thank you.
<table id="ContentPlaceHolder1_dvRecipeItem">
<tr><td>Id</td><td>8</td></tr>
<tr><td>Item Number</td><td>10441</td></tr>
<tr><td>VersionNumber</td><td>6</td></tr>
<tr><td>Modified Date Time</td><td>7/12/2013 17:00:00</td></tr>
<tr><td>Modified By</td><td>enard@clove.net</td></tr>
</table>
the aspx (right now the value comes from the entity data source
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="ItemNumber" HeaderText="Item Number" SortExpression="ItemNumber" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="VersionNumber" HeaderText="VersionNumber" SortExpression="VersionNumber" ApplyFormatInEditMode="True" />
<asp:BoundField DataField="ModifiedDateTime" HeaderText="Modified Date Time" SortExpression="ModifiedDateTime" ApplyFormatInEditMode="True" ReadOnly="true"/>
<asp:BoundField DataField="ModifiedBy" HeaderText="Modified By" SortExpression="ModifiedBy" ApplyFormatInEditMode="True" ReadOnly="true" />
</Fields>
vb.net codePrivate Sub dvRecipeItem_DataBound(sender As Object, e As EventArgs) Handles dvRecipeItem.DataBound
Dim strModifiedBy As String = System.Web.Security.Membership.GetUser.UserName.Trim
CType(Me.dvRecipeItem.Rows(4).FindControl("ModifiedBy"), TextBox).Text = strModifiedBy
End Sub
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, that was the fix. although I had to replace .Value with .Text at the end
Thank you!
Thank you!
Can you post the markup that is produced for that field at runtime? Either that or you could try something like:
Open in new window