Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ObjectDataSource field accessing using C#

Posted on 2007-11-16
4
Medium Priority
?
754 Views
Last Modified: 2013-11-26
Using Visual Web Developer 2005 Express and concentrating on C#

My C# knowledge is limited but want to do this in C# if possible, if its not it would at least let me sleep tonight.

I have added a ObjectDataSource and pointed a Formview component to it successfully (and it works !!!)

In the C# Page_Load i want to access a field in the ObjectDataSource and have not the foggiest idea how to do it, i don't just want to DataBind the field i want to get it into a String so i can beat up the value, whisk it slightly then eventually stuff it out again.

I have been able to create a new SqlConnection and get the field that way its just that i'm annoyed that i can't figure out how to get the field that is already available on the ASP component !

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string WhatsTheValue = ObjectDataSource1["GIVEMETHESTUPIDVALUE"];
        }

    }


0
Comment
Question by:corbpm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 20298140
not sure.. if you need a value from the data you fetched and boud to contol and on postback you are finding value?

but from datasouce you can get and set QueryText .. like
ObjectDataSource1.SelectCommand and others... but not value
for value you must look into the control which you have bound with datasource?
thanks
0
 
LVL 6

Accepted Solution

by:
ventaur earned 2000 total points
ID: 20298411
You can get at the value, but only via the FormView, after it is data bound to. Check out the code below.
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" OnDataBound="FormView1_DataBound">
...
 
 
protected void FormView1_DataBound(object sender, EventArgs e) {
	// Get the data item after type casting it appropriately (assuming a DataSet or DataTable).
	// * Cast to a business class if using that approach.
	DataRowView Data = FormView1.DataItem as DataRowView;
	if (Data != null) {
		string SomeValue = (string)Data["SomeValue"];
		// Do some stuff with the value or get another value.
	}
}

Open in new window

0
 
LVL 6

Expert Comment

by:ventaur
ID: 20298439
If that doesn't suit your needs, get the data via a connection, command, data adapter, and DataSet. Then, get your value(s) to manipulate accordingly from the DataSet. Finally, manually bind the data to the FormView.

FormView1.DataSource = Data.Tables[0]; // Data is the DataSet filled.
FormView1.DataBind();
0
 

Author Comment

by:corbpm
ID: 20298714
Thanks that works !!!!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question