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";
}
}