Getting value from FormView

B

BB

Hi,
I am using FormView Contol, TextBox (Hidden ) and Submit button
whose caption is "View Page" in my aspx page.
Here is what I am tryin to do.When page loads I generate dynamic
url in text box . I want to append exisitng value in Formview field
"CustomeID" to url. When userclicks on "view page" ,new window is
opened with dynamic url.

I am able to do generarting url dynamically, but dont know how i can
do rest of the things. Any idea?

<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
CellPadding="4" DataKeyNames="CustomerID"
DataSourceID="AccessDataSource1" ForeColor="#333333"
OnDataBound="FormView1_DataBound">
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#C0FFC0" />
<EditItemTemplate>
<table>
<tr>
<td style="width: 344px">
<span style="font-size:
9pt"><strong>ID:</strong></span></td>
<td colspan="2">
<asp:Label ID="IDLabel1" runat="server" Text='<%#
Eval("CustomerID") %>' Font-Names="Arial"
Font-Size="8pt"></asp:Label></td>
</tr>
<tr>.....

How I can get value of "IDLabel1" may be in page load or
databound event of page? so that I can concanate value of IDLabel1 to
my url


Thank you
 
K

KJ

After you have databound the fomview, using the following style of
coding to get the value of IDLabel1:

Label IDLabel1 = (Label)FormView1.FindControl("FormView1");
string MyValue = IDLabel1.Text;
 
K

KJ

Sorry, I screwed up the first code line, it should be:

Label IDLabel1 = (Label)FormView1.FindControl("IDLabel1");
 
B

BB

Hi,

Thank you for your response. Here is what I did...

Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sLabel As WebControls.Label

sLabel = FormView1.FindControl("IDLabel1")
TextBox1.Text = TextBox1.Text & sLabel.Text
End Sub

I get following error...Any Idea?

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 19: sLabel = FormView1.FindControl("IDLabel1")
Line 20: TextBox1.Text = TextBox1.Text & sLabel.Text
Line 21: End Sub
Line 22: </script>


Thamk you
 
K

KJ

Now I see.

In the DataBound method, you can use the Row property of FormView1 to
programmatically access the FormViewRow object that represents the
current data row.

The data row contains different content based on the template that is
rendered for the current mode (specified by the CurrentMode property).

You can only access the contents of the template for the current mode.
This means that you will only be able to find IDLabel1 using this
technique if the FormView1 is in Edit mode (e.g., using the
EditItemTemplate containing IDLabel1).

Check FormView1.CurrentMode and see what you come up with. If the value
is not FormViewMode.Edit, you cannot get the IDLabel1.
 
B

BB

Well...Logic behind this is ...
When page is loaded I create link in text box which is invisible. I
have "Preview" button when user click it , It takes url from invisible text
box and goes to that link. Now when form is loaded. IDLabel1 value is
already there displayed. I just need to take that vale and pass as
querystring. ..like ...?iGroup=IDLabel1.text
User interface will be...
User open this form. Selects record to edit using previous next
link buttons on FormView.then Click edit . Make necessary changes. Save
changes. and click on "Preview" button.

Any idea how I acheive this?
 
K

KJ

I'm a little confused: are you saying that the value of IDLabel1 is
never changed by the user?
 
B

BB

Yes..Since its a label. User cannot change value. He can edit other fields
but not IDLabel1..
 

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

Top