Hi - I have a GridView with 3 BoundFields. The GridView is editable and I need to limit the length of each of the possible user input to each of the 3 BoundFields, the first one to 100 characters, the 2nd to 2000 characters, and the 3rd to 200 characters. I've tried adding an attribute to the appropriate Cell in the appropriate Row using javascript on RowEditing, but it doesn't seem to be doing anything. I've figured out how to affect the fields on RowCreated (I can change the font color at least), but I can't find anything on how to address BoundFields on RowEditing.
Here's the GridView definition and the line of code that I'm using:
<asp:GridView ID="gvItin" runat="server" BorderWidth="1px" BorderStyle="Solid" BorderColor="#E8E1C8" AlternatingRowStyle-BackColor="#E8E1C8" AutoGenerateColumns="False" Width="726px" CellPadding="3" Font-Names="Verdana" Font-Size="XX-Small" OnRowEditing="EditGV" OnRowCancelingEdit="CancelEditGV" OnRowDeleting="DeleteGV" OnRowUpdating="UpdateGV" DataSourceID="sds3" DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
OnRowCancelingEdit="CancelEditGV" OnRowDeleting="DeleteGV" OnRowUpdating="UpdateGV" DataSourceID="sds3" DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
Width="726px" CellPadding="3" Font-Names="Verdana" Font-Size="XX-Small" OnRowEditing="EditGV" OnRowCancelingEdit="CancelEditGV" OnRowDeleting="DeleteGV" OnRowUpdating="UpdateGV" DataSourceID="sds3" DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
OnRowCancelingEdit="CancelEditGV" OnRowDeleting="DeleteGV" OnRowUpdating="UpdateGV" DataSourceID="sds3" DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
DataKeyNames="ID" OnRowCreated="SetLength" >
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" />
<HeaderStyle BackColor="#E8E1C8" ForeColor="#9E1414" HorizontalAlign="Left" /><RowStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />
<EditRowStyle Wrap="false" /> <Columns>
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" Visible="False" ReadOnly="True" SortExpression="ID" />
SortExpression="ID" /><asp:BoundField DataField="TripDate" HeaderText="TripDate" SortExpression="TripDate" /> <asp:BoundField DataField="TripLocation" HeaderText="TripLocation" SortExpression="TripLocation" /><asp:BoundField DataField="TripPhoneNum" HeaderText="TripPhoneNum" SortExpression="TripPhoneNum" />
</Columns>
<asp:BoundField DataField="TripPhoneNum" HeaderText="TripPhoneNum" SortExpression="TripPhoneNum" />
</Columns>
<AlternatingRowStyle BackColor="#E8E1C8" />
</asp:GridView>
protected void SetLength(object sender, GridViewRowEventArgs e)
{
foreach (TableCell cell in e.Row.Cells)
{
cell.Attributes.Add("onkeypress", "if(this.value.length>10) return false;");
}
}
Any help would be much appreciated!