Finding controls in datagrid in user control

Hi, here's the scenario. I had a datagrid in a page, worked fine. I've moved the datagrid to a user control, and the update code I had does not work anymore.

 

In the datagrid, I have:

OnUpdateCommand="update_user"

 

In the class for the user control, I have:

 

Protected Sub update_user(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

 

then later, as part of a loop that cycles through the field names - data_field(x):

 

Dim drop_down As DropDownList = CType(e.Item.FindControl(data_field(x)), DropDownList)
sql_comm.parameters.add("@" & data_field(x), drop_down.SelectedItem.Value)

 

This produces the irritating error on the line beginning with sql_comm:

Object reference not set to an instance of an object.

This is probably related to the datagrid control being placed in the user control, but I don't see why.

 

If you need more info I'd be happy to oblige!

 

Thanks,

Drew

0
anught
12/2/2005 7:24:48 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
756 Views

Similar Articles

[PageSpeed] 33

Please disregard my post. (Is there a way to cancel posts?)

Seems that I've been solving my own questions before they're even approved for the forum!

The problem was NOT with the datagrid being placed in a user control. It works fine.

The issue instead was part of a case selection scheme I had setup without accounting for a particular case, so the control was simply not there.

My debugging had led me to believe the data_field(x) contained a particular value when in fact it contained something else. Manual debugging through error trapping brought out the problem and it's been resolved.

Thanks to anyone who considered the problem!

Drew

0
anught
12/3/2005 2:16:04 PM
Reply:

Similar Artilces:

User Control controls not created when dynamically creating user control
  Have created a user control for displaying and editing a dynamically number of values. The user control contains two labels and an edit box. When dynamically loading the user control I get an error when the control itself tries to change setting on the fields within the user control.   Why doesnt this work? It works okay if I dont load it dynamically but create a user-control-instance in the aspx-page but thats no solution.   Thankyou!     Here is my code:   ucDataValue.ascx   <%@ Control Language="C#" AutoEventWireup="true&...

How to access a user control from another user control in a Wizard control
My page has a wizard control and each step is a user control.  I could find the value of a control in step1 user control in the wizard page but not in step2 user control.From wizard.aspx.vb – it worksDim m_title As DropDownList = CType(Me.PersonalBox1.FindControl("ddlTitle1"), DropDownList) Question:How can I find the value of a control(textbox or dropdownlist)in step1 user control from step2 user control? I want to find “PersonalBox1.FindControl("ddlTitle1")” from Step2 AddressBox1. I have tried several ways to access it but no luck. From AddressBox.ascx.vb –...

User Controls not working if I put Validation controls in user control
Hi           I have validation controls(RequiredField Validator,RegularExpressionValidator)  in user controls.User controls are not posting back like the events are not wiring up.If I remove Validation controls in User controls page,user controls are working fine.Can anyone please help me out in getting it fixed. In the Validation controls, make sure you are setting the ControlToValidate property to the control that it links to.  If you're in .NET 2.0, it's also a good idea to put all the validation controls in the same Valid...

How do you control the placement of controls in a user define control
I have a user define control.  I put the control on the (C# Visual Studio 2008) page where I want them. When I run the program, the controls are all over the page.  How do I place them where they do not move form where I put them? You'll need to study the HTML output and see what it's producing, then start to look at how to do an HTML layout. hi, there are absolute and Relative position in html. I guess you must use relative position. For example, at design-time, you place a TextBox below an Image, at run-time, no matter what size is the image, the TextBox is alway bel...

User Control in a User Control
I have a first user control that contain a second user control. If I cahe the first user control can I still dynamically control the second one or it is cached with the first one therefore can not control it anymore? Thanks When your first control is cached, its rendered out and its output is stored in the cache. On every request to the page containing your control that can satisfy it from cache, the output will just simply be inserted - your first control will never be instantiated or run in that case, so the second one wont be either. Hope this helps,Mike VolodarskyProgram Manager...

User Controls in User Controls?
I have the follow set up and it is throwing an error "Unhandled error loading module" ... is there some trick to this that I don't know?I have a project A that uses controls from project B (project B is just a project with all my user controls used through out other modules).  project A uses user control 1 from project B with out any issues at all - great.  But then I wanted to add user control 2 to user control 1 and that is when I get my error.  In fact I don't even have the user control 2 in user control 1, just when I put the register part into user control 1 is when it al...

user control to user control
I have an aspx page that have a "Register" directive to two usercontrol called rptMaster.ascx and rptDetail.ascx. I'm trying to set up a Master-Detail relationship and wish for the rptMaster.ascx to trigger and event from a dropdownlist and for the rptDetail to be listening for DropDownList event. I believe I have gotten the events part okay with help from this articel http://codeproject.com/aspnet/Page_UserControl.asp but my declaration for a private statement to my rptMaster class is producing an error. I'm using beta 2 of asp.net and I 'm having trouble getting a reference TO ...

User control in a user control
Hello all, I have created a user control with some checkboxes, and public properties to get the values of these checkboxes. I have also created a second user control using the first user control; this second control also access the public properties of the first one. My problem is when I implement the second control in an aspx page, if I click at runtime the checkboxes in the first control, I am able to access its public properties from the methods of the second control but the values of these properties are wrong. while at design time, I do not have this problem. Than...

Finding Accurate client ID of controls placed in user control in nested control scenario
Hi In my application i need to access value of an asp lable which is placed in user control (i have a separate javascript file for each usercontrol) this user control can be placed anywhere now i need to acces this value. As we frequently need to access a control by its client id can we have some client event like initialize or something like pageload (for usercontrol) where i give the function name with the arguments containing the client id . let me know if i need to explain my case in more detail -amit    on the server you can figure the client id  me.namingcontaine...

Finding Controls from User Control issue. C#.NET 1.1
Okay, I have a user control that opperates on a DataGrid. I have a Page which has a DataGrid my userControll on it. My User Control needs to operate on that Datagrid (and hold it's formation through post-backs, not in the viewstate). So the only thing I can think of is to find the DataGrid by it's name, which is set in the html as the public property string DataGridName: public string DataGridName         {             set             {     &n...

Updating a Label control in one user control from another user control
Hi all, I have a main page in my music store site that has 5 user controls on it with 1 always showing main content and the others being things like a shopping cart, "best sellers", genre list etc (a la amazon). From the main content control I want to be able to set some label controls in my shopping basket control but I just can't seem to work out the syntax for how to do this: Here's the code I'm using - I'm trying to go to the 4th user control on the page (my shopping basket) then find the appropraite label, cast it locally as a Label then update the value: Label _so...

controlling user controls
I'm starting an app. I'm using a usercontrol for a template. In my "template" I have a usercontrol that at times displays a login form. In this usercontrol is a link to the register page. Currently, my register page works by just calling my register user control in the main content area of the template. I'd like to cut out the register.aspx so that the link simply tells the other area on my page to display the register.ascx. So that I don't have several pages... just one default.aspx. How do I do this? I'm thinking the template.ascx will have a placeholder in the main...

Finding control in templated user control
Hi guys, I created a templated user control modeled after: http://msdn2.microsoft.com/en-us/library/36574bf6(vs.71).aspx So now in a page that instantiates the user control it looks like... <uc:MyControl ID="myControl" runat="server"><MyTemplate><asp:Literal id="ltlTest" runat="server" /></MyTemplate></uc:MyControl> The problem is I can't figure out how to find controls within the template (such as ltlTest seen above.) If I add watch I can find the placeholder control but can't find my controls anywhere in the...

Finding control in another user control
I have a page that's made up of 3 different controls.  I'm trying to reference a control in the "left" control in the code of the "middle" control.  Here's what I'm trying:Dim oShelf = CType(Me.Page.FindControl("ddl_myShelf"), DropDownList)  Response.Write(ddl_myShelf.SelectedItem) I'm getting an Object reference not set to an instance of an object error when trying to do this.  What am I doing wrong?  My ultimate goal is to refresh the control ddl_myShelf.  Thanks. I think, if I understand you correctly, you're trying to make things too hard ...

Web resources about - Finding controls in datagrid in user control - asp.net.presentation-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Grand Mufti of Australia in damage control after Paris attacks
AUSTRALIA’S top Muslim cleric has gone into damage control.

New solution helps businesses take control of CRM
... Azuqua is launching a purpose-built solution to allow businesses to integrate data, automate business-critical workflows and take control of ...


Obama to Veto Bill Requiring Background Checks On Syrian Refugees; France Demands Tighter Controls, EU ...
... does not call for ending the refugee program or require religious screenings, as some Republicans have demanded . France Demands Tighter Controls, ...

2 Killed After Helicopter Spins Out Of Control, Bursts Into Flames At Southern California Airport
Two people on board a helicopter were killed when the aircraft spun out of control after landing and burst into flames in Carlsbad.

We Face Terrorist Threats – Don’t Even Think About Enacting Gun Control Laws
Because, "terrorists have once again proven that only good people obey bad laws, and they do so to their own detriment."

This App Lets You Control Your Smartphone By Drawing
Mouse gestures never made sense on PCs, but they're awesome on Android. Long before we started swiping and tapping on touch screens, mouse gestures ...

How To Take Control Of The New Apple TV's Siri Remote
... is jumpy? Tired of scrolling back and forth to switch between Uppercase and Lowercase text? Here are some tips to let you quickly take control ...

Obama: I’m thinking I’ll spend my last year in office focused on gun control
Plans. Your alternate headline comes from Charles Cooke: “President Obama announces record gun sales in 2016.” So two of his major priorities ...

Resources last updated: 11/21/2015 6:34:24 AM