.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Why it returns null (GridView)TemplateContainer.FindControl("gridView")?

Posted By:      Posted Date: October 06, 2010    Points: 0   Category :SharePoint


I created a new custom field definition.

But on CreateChildControls event it always return null in my components. Where is error? What should I do to make work it properly?


protected override void CreateChildControls()


if (this.Field == null) return;


if (this.Field != null && this.ControlMode!= SPControlMode.Display)

this.MyPrefix = (Label)TemplateContainer.FindControl("MyPrefix");
if (this.MyPrefix == null)
    throw new ArgumentException("Corrupted PermissionControl template - missing ProofHQUserPermissionPrefix.");
this.gridView = (GridView)TemplateContainer.FindControl("gridView");
if (this.gridView == null)
    throw new ArgumentException("Corrupted PermissionControl template - missing GridView.");



All components are defined in template PermissionControl.

View Complete Post

More Related Resource Links

RowCommand returns null value for controls which are not binded to Gridview source


I am tryting to reach controls in the gridview rows by RowCommand event. I can take values of controls which are binded to gridview source successfully . But for all other controls which is not binded to gridview returns NULL value. All controls run at server. Why is that?

GridView EmptyDataTemplate and FindControl Method


I have 2 textboxes, a dropdownlist and a button in the EmptyDataTemplate of a GridView control and when I click the button I want to get the text from the text boxes and DropDownList put it in the QueryString of a URL i redirect to, but I can't work out why the FindControl method cannot find the controls.  I am using the following code:

Dim ddlNumPpl As DropDownList = GridView1.FindControl("ddlNumPpl")

I get an "Object reference not set to an instance of an object" error though when I try to refer to the SelectedValue property of it though.  I would be very grateful if someone could let me know why the FindControl method can't find the control and what I should do to rectify it.

Many Thanks (in advance),


Gridview RowCommand Event returning null values

HiI'm trying to retreive values entered by users in the textboxes in the footer of the gridview and insert these values into another sql table.My code is as follows :-protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)    {       if(e.CommandName.Equals("addnew"))       {                       TextBox t1 = (TextBox)GridView2.FooterRow.FindControl("tfrm");            string frm = t1.Text;            TextBox t2 = (TextBox)GridView2.FooterRow.FindControl("tsub");            string sub = t2.Text;            string cmd = "insert into suggestions values('" + frm + "','" + sub + "','c','c')";            con.Open();            SqlCommand com = new SqlCommand(cmd,con);            int a = com.ExecuteNonQuery();&n

FindControl returns null

I am trying to fetch two Labels within a Repeater element to attach data to; which Label is assigned which Data Field depends on the result of a Radio Button List, hence why I need to fetch them in the code behind. This is the ASP.NET code: <asp:View ID="vwSportType" runat="server"> <table> <tr> <td rowspan="2"> <span class="boldtext">Select type of sport:</span><br /><br /> <asp:ListBox ID="lbType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="lbType_OnSelectedIndexChanged" Height="300px" Width="12em"> </asp:ListBox> </td> <td width="70%"> <span class="boldtext">Show by: <asp:RadioButtonList ID="rbSportType" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Text="Date, Sport" Selected="True" Value="0"></asp:ListItem> <asp:ListItem Text="Sport,

findcontrol problem in a gridview

Hey guys I've got a gridview with a few textboxes in each row which I want to insert into a database, after a user clicks a submit button (thats outside of the gridview)  This is my code for the gridview<asp:GridView ID="GridView2" AutoGenerateColumns="false" runat="server" EnableModelValidation="True"> <Columns> <asp:TemplateField > <ItemTemplate> name: <asp:Label ID="Label12" runat="server" Text='<%# Bind("PlayN") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="TxtFirst" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="txtLast" runat="server"></asp:TextBox> </ItemTemplate>

GridView Rowupdating Returns old Values


Haii all, my gridview row updating events return old values.. edititem templatefield gets its old value on row updation.

My code is as follows :-

      protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

        TextBox tb1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt3");
        TextBox tb2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt4");
        TextBox tb3 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt5");
        TextBox tb4 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt6");
        TextBox tb5 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt7");

        string s1 = tb1.Text;
        string s2 = tb2.Text;
        string s3 = tb3.Text;
        string s4 = tb4.Text;
        string s5 = tb5.Text;

        string qry="Update SparePartsStatus set Equipment='"+s1+"',Location='"+s2+"',TotalQuantity='"+s3+"',DateofDelivery='"+s4+"',Balance='"+s5+"' where (SpareName='"+Session["partno"]+"')";
SqlCommand com=new SqlCommand(qry ,con);
        int d = com.ExecuteNonQuery();


NULL value of Gridview inside Datalist


I am using a gridview, which is inside datalist, but whenever I try to serach gridview in datalist it reyurns NULL. I using the following code, bolded line is not able to assign gridview:

amespace DataListXML
    public partial class _Default : System.Web.UI.Page
        DataSet _dataSet;
        protected void Page_Load(object sender, EventArgs e)

GridView and FindControl issue..


Hi guys,

I dont seem to find any control using the FindControl method over gridviews "on edit". I have pasted my code below, please tell me if m doing something wrong or missing something..

ASPX page:

<asp:GridView ID="gvCountry" runat="server" AutoGenerateColumns="False" 
                <asp:TemplateField HeaderText="Edit">
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update"></asp:LinkButton>
                         <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 

Grouping gridview with gridhelper returns wrong row index



I'm using a GridView and GridViewHelper Class (http://www.agrinei.com/gridviewhelper/gridviewhelper_en.htm) for grouping the grid by desired field. On the grid I also include an "edit" RowCommand.



ID ... Name ... Company ... Year ... RowCommand



1 ... Alex ... Comp1 ... 1999 ... Edit

2 ... Jane ... Comp2 ... 1999 ... Edit


3 ... Mike ... Comp1 ... 1999 ... Edit

Now when I click edit in the second row of the grid (ID=1, the Group itself is shown in the first row) I have the following code on RowCommand:

// Convert the row index stored in the CommandArgument
                    // property to an Integer.
                    int index = Convert.ToInt32(e.CommandArgument);

                    // Retrieve the row that contains the button clicked 
                    // by the user from the Rows collection.
                    GridViewRow row = GridView1.Rows[index];

and the index returned is 0 instead of 1. Why? And how can I fix this, because the edit command returns error or points to the wrong records??<

Show column headers when gridview returns empty data set




I have in my code a gridview that I redirect to excel, it works fine when I have data in the data set. waht I want is to show column headers when there is no data right now what i get is empty sheet. 

Gridview with null values


 In a search by address page, I have two text boxes to enter street number and/or street name. User can enter both the values or any one and click Search button. The matching data will be in a grid below.

My problem: sometimes the Street number column has null values. In those cases if I search by a street name that does not has a street number, nothing was coming. So I have changed the query as follows:

SELECT     ChurchID, PK_ApplNo, ADDDTTM, ADDBY, MODDTTM, MODBY, AppDate, Applicant, StreetNumber, StreetName, MagisterialDistrict,
                      UndisturbedOpenSpace, RearYardFt, MaxApprovHeightFt, NumberofSeats, NumberofParkingSpaces, ChildCareCenterCCC, NoofStudentsinCCC, School,
                      NoofStudentsinSchool, NurserySchool, NoInNurserySchool, BZABOSAction, BZABOSHearing, StaffRecommendation, SubjectComment, DateofDecision,
                      CornerLot, DPZ_BZA_BOSActionComment, NumberofSeats / NumberofParkingSpaces AS Ratio
FROM         tb

Nested GridView Control returns "Object variable or With block variable not set" when outer GridView


Nested GridView Control returns "Object variable or With block variable not set" when outer GridView returns rows.

The Nested GridView Control works as long as the outer GridView returns rows, the following code works:


Protected Sub GridViewReport_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewReport.RowCreated

          If e.Row.RowType = DataControlRowType.DataRow Then

                 Dim myStatus_ID As SqlDataSource = CType(e.Row.FindControl("sqlDeviceStatusAssign"), SqlDataSource)
                 If Not e.Row.DataItem("Status_ID") Is Nothing Then
                                  myStatus_ID.SelectParameters(0).DefaultValue = e.Row.DataItem("Status_ID")
                 End If

       End If

Gridview Null all values , Javascript


I did following code in vb.aspx, how I do following code in Javascript script,

Gridview1.EmptyDataText = "Data Not Found !"
Thanks in advance.

gridview cell value via FindControl......


I have a page that is using an unbound gridview, that has a mixture of template based columns (drop down list, text boxes, etc).  I've tried the following syntax to retrieve the values currently in the cells.


 TextBox1.Text = grdDataEntry.Rows(1).FindControl("mydropdownlist").ToString        

TextBox2.Text   = grdDataEntry.Rows(1).FindControl("mytextbox").ToString


What am I missing???

Inplace Edit in GridView

In this article I am presenting a different way to look at EditItemTemplate, using which user navigation for editing is reduced and . it looks very different (see screeen shots) then regular implementation of GridView.

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend