Jim,
Word on the street is that you know everything about .Net. Well I am
just learning ASP.Net 2.0 and have question. Maybe you can help?
I am using a Formview to display data from a SQL database. This part
works fine. Where I have a challenge is that I would like to pull a
value from the Formview (e.g. Company Name) and display it in a label
on the same page but outside of Formview control.
I am using ASP.Net 2.0 with C# and code behind pages.
Do you know how to do this?
The specific field that I want to grab the value from in the Formview
is RefTemp_Client_Company_NameLabel. I want to put that value in
Label1.
Thank you,
Robert Vaughn
Albuquerque, NM
Following is the code from the test.aspx.cs file
/////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Label1.Text = "Original value";
//Label1.Text = FormView1.???????
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
Following is the code form the test.aspx file…
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"
Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:EIL_Requirements_DatabaseConnectionString %>"
SelectCommand="SELECT [RefTemp_Client_Company_Name],
[PK_RefTemp_Name] FROM [Reference_Template]">
</asp:SqlDataSource>
</div>
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="PK_RefTemp_Name" DataSourceID="SqlDataSource1">
<EditItemTemplate>
RefTemp_Client_Company_Name:
<asp:TextBox ID="RefTemp_Client_Company_NameTextBox"
runat="server" Text='<%# Bind("RefTemp_Client_Company_Name") %>'>
</asp:TextBox><br />
PK_RefTemp_Name:
<asp:Label ID="PK_RefTemp_NameLabel1" runat="server"
Text='<%# Eval("PK_RefTemp_Name") %>'>
</asp:Label><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
RefTemp_Client_Company_Name:
<asp:TextBox ID="RefTemp_Client_Company_NameTextBox"
runat="server" Text='<%# Bind("RefTemp_Client_Company_Name") %>'>
</asp:TextBox><br />
PK_RefTemp_Name:
<asp:TextBox ID="PK_RefTemp_NameTextBox"
runat="server" Text='<%# Bind("PK_RefTemp_Name") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
RefTemp_Client_Company_Name:
<asp:Label ID="RefTemp_Client_Company_NameLabel"
runat="server" Text='<%# Bind("RefTemp_Client_Company_Name") %>'>
</asp:Label><br />
PK_RefTemp_Name:
<asp:Label ID="PK_RefTemp_NameLabel" runat="server"
Text='<%# Eval("PK_RefTemp_Name") %>'>
</asp:Label><br />
</ItemTemplate>
</asp:FormView>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></
asp:Label>
</form>
</body>
</html>