|
-
May 21st, 2012, 03:37 PM
#1
Thread Starter
New Member
Error: Does not exist in current context C#
Hey guys, I have an issue with C# I am trying to set a detailsview with dataset info like:
DetailsView1.DataSource = ds123;
DetailsView1.DataBind();
It is from inside a Gridview SelectedIndexChanged event handler, but it is giving me an error message "DetailsView1 does not exist in current context.
How do I fix this?
-
May 21st, 2012, 06:57 PM
#2
Re: Error: Does not exist in current context C#
Check where you defined your DetailsView1 If it is defined in a procedure then it will not be accessable outside the procedure where it resides.
Define your vars at the top of the class to make them available to all procedures within a class.
-
May 21st, 2012, 07:25 PM
#3
Thread Starter
New Member
Re: Error: Does not exist in current context C#
Hey Datamiser, the detailsview1 is defined in an .ASPX page called default2.aspx in the markup. The c sharp code is sitting in a page called Default2.aspx.cs inside the function protected void View1_SelectedIndexChanged for a grid view, how would I declare detailsview1 so that I can use it inside here?
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
Last edited by coxmg; May 21st, 2012 at 07:32 PM.
-
May 21st, 2012, 08:43 PM
#4
Re: Error: Does not exist in current context C#
If you want the object to be available to the entire class then you define it at the top of the class after the initial {
-
May 22nd, 2012, 12:37 PM
#5
Thread Starter
New Member
Re: Error: Does not exist in current context C#
I got it to recognize the detailsview by declaring:
protected global::System.Web.UI.WebControls.DetailsView DetailsViewBase;
but now it says this details view is NULL, how do I assign it to what is on the webpage?
-
May 23rd, 2012, 03:28 AM
#6
Re: Error: Does not exist in current context C#
I'm not sure what you mean but with the detailsview you can select a data source via the "Details View Tasks", choose a new data source type, choose data connection then configure the select statement.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 23rd, 2012, 12:08 PM
#7
Thread Starter
New Member
Re: Error: Does not exist in current context C#
Hey Nightwalker, no, that's not what I need for the detailsview assignment. Excuse me for being a bit new with C#.net. Here's what I need, I just need to make a manual assignment to a details view object on a .NET webpage via C# code.
For example, take the string "XYZ" that you create in a string variable in C#, and then assign that to a field called "Zipper" on a details view called DetailsView1 sitting on a webpage called Default.aspx within a selected index changed from gridview, can you show me how to do that in C# code?
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|