Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 5th, 2011, 05:29 PM
Registered User
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Unhappy Error Referencing GridView Template RangeValidator

Like many people, I'm trying to dynamically set the MaximumValue and MinimumValue of the RangeValidator of a GridView template to other column values in the gridview. After much searching, I found a few examples that I am trying to use, but am getting an "Object reference not set to an instance of an object" on the code-behind line starting with "(e.Row.FindControl("RangeValidator1")...". The remarked-out line above it gives the same error.

Here is the code:

Code:
        <EditItemTemplate>
          <asp:TextBox ID="TextBox1" runat="server" 
            Text='<%# Bind("QTY_ORD", "{0:#,###}") %>'></asp:TextBox>

          <asp:RangeValidator ID="RangeValidator1" Runat="server" 
          ErrorMessage="Order Quantity outside of MIN/MAX range."
          MaximumValue="333" MinimumValue="111" 
          Type = "Integer"  
          ControlToValidate="TextBox1">*</asp:RangeValidator> 
                  
        </EditItemTemplate>
Code:
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
   //   (e.Row.FindControl("RangeValidator1") as RangeValidator).MaximumValue = e.Row.Cells[5].Text.Trim();
      (e.Row.FindControl("RangeValidator1") as RangeValidator).MaximumValue = "999";
    } 
  }





Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview Item Template dotnetDeveloper ASP.NET 3.5 Basics 0 February 15th, 2010 02:01 PM
RangeValidator and decimal separator wakeup ASP.NET 2.0 Basics 0 February 8th, 2010 06:52 AM
GridView Template Field ktpatel ASP.NET 2.0 Professional 0 January 21st, 2009 10:07 AM
Need to get value of gridview template columns for kmh030 ASP.NET 2.0 Professional 1 January 6th, 2007 11:10 PM
referencing an object in an edit item template dan195 ASP.NET 1.0 and 1.1 Basics 3 September 25th, 2006 07:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.