variable lost between DetailsView1_DataBound and DetailsView1_ItemCreated

M

Mich

Hi,

I need the value of one field in the detailsview (in normal mode) in order
to make a test when creating items.
I get that value, put it into a friend variable, but when fetching it from
the ItemCreated event, it's empty.
Why does it lose its value and how to solve that?

Thanks for help
Mich

<asp:DetailsView ID="DetailsView1" runat="server" ...
DataSourceID="SqlDataSource1" >
<Fields>
<asp:TemplateField HeaderText="myfield">
></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("myfield")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</fields>


code-behind:
------------
.....
Friend st As string
.....
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
If DetailsView1.CurrentMode = DetailsViewMode.ReadOnly Then
Dim dvr As DetailsViewRow
Dim lb1 As String
For Each dvr In DetailsView1.Rows
lb1 = CType(dvr.FindControl("label1"), Label)
Next
st=lb1.text
End If
response.write(st) 'this works
End Sub

Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.ItemCreated

if st="ok" then 'st is empty
.....
 
G

Guest

Mich,

AFAIK, ItemCreated is fired PRIOR to DataBound event - therefore at the time
you are trying to read it is is not set yet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top