Find Control returning null ?

Hi,

         I have nested grids on a form, there is a grid inside a template field of a gridview which I'm accessing via findcontrol, however after Insertion of one record and generating the child gridview the next time when I try to access it I get a null returned on find control ( the gridview is already there)

 

if (e.Row.RowType == DataControlRowType.DataRow)
        {

            

            if (ViewState["SecTab"] != null)
            {
                GridView gvSecShComm = (GridView) e.Row.FindControl("gvSec");
                Int32 CompID = Convert.ToInt32(((DataRowView)e.Row.DataItem)["Code"]);

                DataTable dt = new DataTable();
                dt = (DataTable)ViewState["SecTab"];

                DataView dv = new DataView(dt);
                dv.RowFilter = "IDC="+CompID;
                dv.RowStateFilter = DataViewRowState.CurrentRows;

                if (dv.Count > 0)
                {
                    gvSecShComm.DataSource = dv;
                    gvSecShComm.AutoGenerateColumns = false;
                    gvSecShComm.AllowPaging = false;
                    BoundField bfSecName = new BoundField();
                    bfSecName.DataField = "Sec.";
                    BoundField bfSecShare = new BoundField();
                    bfSecShare.DataField = "Share";
                    BoundField bfSecComm = new BoundField();
                    bfSecComm.DataField = "Comm.";
                    gvSecShComm.Columns.Add(bfSecName);
                    gvSecShComm.Columns.Add(bfSecShare);
                    gvSecShComm.Columns.Add(bfSecComm);
                    gvSecShComm.DataBind();
                }      
                    
                


            }
        }
  
0
asp_crazy_guy
5/5/2009 4:15:38 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
3878 Views

Similar Articles

[PageSpeed] 57

 instead of this

GridView gvSecShComm = (GridView) e.Row.FindControl("gvSec");
 
try this
GridView lblRoomTypeCode = (GridView)e.Item.FindControl("gvSec"); 

 


Please mark as answer if it helped u!
0
kavita_khandhadia
5/5/2009 5:05:21 AM

Hi,

Findcontrol willl return null if the parameter which you are passing is not existing. Check once again the gridview id. Are you creating grid view dynamically??


Thanks And Regards,
Fayaz
Chennai, India


Please remember to click “Mark as Answer” on the post that helps you
0
fayaz_3e
5/5/2009 5:13:24 AM

kavita_khandhadia:

try this
GridView lblRoomTypeCode = (GridView)e.Item.FindControl("gvSec"); 

 

Hi,

I think there is no e.Item attribute in GridView.. it should be e.Row.. e.Item will only work for DataGrid..


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
5/5/2009 5:15:46 AM

 Thanks guys I found the problem. Actually I had placed the child gridview inside the same column as the save button in edit template field. Like gridview was on Item template field and save button was on edit item template field. So on edit it wasnt locating the control. All is working now. Thanks for the support guys ! SmileYes

0
asp_crazy_guy
5/5/2009 5:25:23 AM

When page loads on the browser, right click and go to view source.

Find gvSec, I believe you won't get it, its id must be something else.

Replace the gvSec in FindControl with the name of the gridview which you get in view source

GridView gvSecShComm = (GridView) e.Row.FindControl("gvSec");


Please mark it as answer if it resolves the issue.

visit: http://technicalsol.blogspot.com
0
sumitd
5/5/2009 5:26:40 AM

kavita_khandhadia:

 instead of this

GridView gvSecShComm = (GridView) e.Row.FindControl("gvSec");
 
try this
GridView lblRoomTypeCode = (GridView)e.Item.FindControl("gvSec"); 

 

I am surprised, this has been marked as answer.

Can any one let me know how can we get Item property in GridView?

As the orginal post doesn't tell which event, so i believe user must be trying RowDataBound and "e.Item" doesn't exist.

Please let me know your thoughts on it, vinz has already mentioned in the post.

 

 


Please mark it as answer if it resolves the issue.

visit: http://technicalsol.blogspot.com
0
sumitd
5/5/2009 5:47:52 AM
Reply:

Similar Artilces:

BUG: Image Controls in UpdateProgess Control: Can not use FindControl() methods to get Image
There is a single UpdateProgress control on the page. as such: <ajax:UpdateProgress  ID="UpdateProgress1" runat="server"   DisplayAfter="100" >         <ProgressTemplate>                <div style="border:2px solid #0099FF; background-color:#EFEFEF; padding:10px; width:200px; height:20px;">               Updating Panel            </div&...

Find nested control from within a returned control
*** edited by: master4eva *** Please enclose your code in </ code> tags so that it is more readable online. ********* I have a base class, and a class derived from the base class... the base class has a method that generates an HTML table that, in turn, contains rows which in turn contain cells. (These are the WebControls Table, TableRow, and TableCell.) Here's my problem: In the derived class, I want to call the base class's ReturnTable method, and then sift through that table and update the NavigateURL of a HyperLink in one of the cells, change the ImageUrl of an ...

Finding a control using find control
Hi I am using ajax to load different User controls in a page . When I am using FindControl method to get the reference to the update panel in the main page (i have a master page where script manager list located, then i have my main page which uses the master page and it only contains an update panel and content template(where user controls gets loaded). Inside and event handler of my user cotrol i tried to access the update panel using page.findcontrol(< ID of the update panel>) i got a null value . but when i searched the control hierarchy of the page . i find it(using watch) i...

Find Control not "Finding the control"
I'm trying to figure out why this code is not displaying the ControlID for the TextBox which is in a Datagrid in a TemplateColumn: void editClicked(object sender, DataGridCommandEventArgs e) { // Simple script to display the ControlID of the TextBox txtln message.Text = Convert.ToString((TextBox)e.Item.FindControl("txtln")); } <asp:TemplateColumn SortExpression="ln" HeaderText="Last name"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem,"ln") %> </ItemTemplate> <...

superreview granted: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

superreview requested: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
Aaron Leventhal <aaronleventhal@moonset.net> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

Ajax Control Toolkit: Control cannot be created because Visual Studio cannot find the control's type in the control assembly.
Hi All, Good Day.  I am using ASP.Net 2.0 Framework, i have downloaded Ajax 3.0 and added reference into the project. But i am not able to add controls to the page. When i tried to add control into the page getting following error message "Control cannot be created because Visual Studio cannot find the control's type in the control assembly". I checked some forums on the web, added references in Web.Config. Still not able to proceed further. Please revert asap.  Thanks. AJAX 3.0 not work in 2.0 Framework its work in 3.5 Framework try to download another ...

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...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

control cannot be created because Visual Studio Cannot find the Controls type in the Control Assembly
Hi Friends, I have installed Visual Studion 2005 on my machine. After creating an AJAX FutureRelese Web project. I tried to add Future Release Controls to my web page. I am getting the following error "control cannot be created because Visual Studio Cannot find the Controls type in the Control Assembly" Could you please get back to me with the solution for this. Thanks and Regards, Baburaj P V Pls make sure you have System.Web.Extensions referenced. If Not Add it from the Reference Dialog, it is insalled in the GAC. If you also have the previous version then you have to modify th...

Control cannot be cretaed because Visual Studio cannot find the controls type in the control assembly
This is a possible IDE bug please do the following to replicate 1.Create a new Web application 2.Create a new class library project called ClassLibrary1 3.Create a new WEbCustom control in ClassLibrary1 called WebCustomControl1 4.Create a new class library project called ClassLibrary2 5.Create a bummy interface called interface1 in ClassLibrary2 6.Implement interface1 by WebCustomControl1 7.complile solution 8.Add the WebCustomControl1 to the toolbox and try to added to a page of the Web application the message of the subject appears is there a way to overcome this ? am i missing ...

Cascading Dropdown error in formview controls and finding all controls in formview controls
can help with the following? Instantiate Cascading Dropdowns within Formview controls (this returns the error message "databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control".) Pass values between controls within master controls such as Textboxes within formviews (example: Pass the selected value in a dropdownlist to another textbox both WITHIN a formview control) Expose the public properties of a master page Hi arraybiz, 1) I need your code. See sample: http://www.mikepope.com/blog/fun/cascadingdropdowns_dy...

control cannot be created because visual studio find the controls type in the control assembly
Hi to all,            I'm working with Asp.Net2.0,VS2005-C# and Crystal Report 11.5.            Whenever i drag and drop the CrystalReportViewer control from Toolbox then i got this error control cannot be created because visual studio find the controls type in the control assembly then i click OK button then it display one more error Invalid Forematetc structure (Exception from HRESULT: 0x80040064(DV_E_FORMATETC) But all other projects i can add the control from toolbox&nb...

Finding a control in a composite control
I have a composite control that is built at run time from a class - one of the controls in it I need to attach an onclick attribute to it.  How do I do that?  I tried the findcontrol method but it returns null.Dylan Barberread my stupid blog http://codemypantsoff.com Debug it, and inspect the Controls collection of your composite control manually in order to see what's going on. Cheers, Wim Wim Hollebrandse---http://www.zealandit.com...

Web resources about - Find Control returning null ? - asp.net.presentation-controls

Returning - Wikipedia, the free encyclopedia
In retail , returning is the process of a customer taking previously purchased merchandise back to the retailer, and in turn, receiving a cash ...

Mark Zuckerberg Returning To TechCrunch Disrupt
Facebook Co-Founder and CEO Mark Zuckerberg took the stage at last year’s TechCrunch Disrupt conference in San Francisco, where he discussed ...

How-to: Improve the Experience for Returning Users
... – your inbox, your favorite news sources, or your friends’ activity. If you’ve integrated Facebook Login on your website, you can give returning ...

Search Twitter - emilia-clarke-not-returning
Sign in Sign up No results for emilia-clarke-not-returning Settings Help Back to top · Turn images off

Is the Returning CEO a Trend?
... well be wondering if it is a new trend for boards to reach back into their alumni ranks to bring back a CEO when a company is in Is the Returning ...

Fire engine returning from a call
District of Columbia Fire & EMS Station No. 3

Zillow: Long Distance (Returning Soldier Commercial) - YouTube
Introducing Zillow's latest TV commercial as part of its national advertising campaign, "Find Your Way Home." The spot, entitled "Long Distance," ...

WWE’s Daniel Bryan on WWE 2K16, facing Brock Lesnar at WrestleMania, returning to the ring and life on ...
The four-time WWE world champion discusses whether it is right for Stone Cold Steve Austin to be the cover star of WWE 2K16, as well as who he ...

Damn Fine News of the Day: Kyle MacLachlan is Returning to ‘Twin Peaks’
In case you missed it, David Lynch announced on Twitter Monday that Kyle MacLachlan will reprise his role as Special Agent Dale Cooper in the ...

Returning Cat Daniel Menzel hopes for a pain-free summer
Having starred in his first match in almost four years, Geelong forward Daniel Menzel says his next major challenge is to train - pain free - ...

Resources last updated: 2/5/2016 6:49:20 AM