datagrid custom validation

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I am adding a custom validator into my datagrid and when I call the
OnServerValidate function, my ControlToValidate isn't recognised. Is
this because a different signature is required when calling the function
from a datagrid?

public void Validate_DCUG(object sender,
System.Web.UI.WebControls.ServerValidateEventArgs value)
{
}


Thanks,

Mike
 
how are you initializing the grid? Is it being added dynamically or it's on
the WebForm already?
Might be missing the viewstate on the postback.

Thanks,
Branimir
 
This is the HTML on my page :

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form ID="Log" runat="server">
<asp:label ID="lbl1" runat="server"></asp:label><BR><BR>
<asp:label ID="lbl2" runat="server"></asp:label>
<div style="vertical-align
top;height:400px;width:570px;overflow:scroll;">
<asp:DataGrid id="dgLog" runat="server"
CellPadding="3"
Font-Name="arial"
Font-Size="8pt"
HeaderStyle-ForeColor="#00015E"
HeaderStyle-BackColor="#dcdcdc"
HeaderStyle-Font-Bold="true"
BorderColor="black"
BackColor="#0099CC"
forecolor="#FFFFFF"
AllowPaging="true"
PageSize="10"
OnPageIndexChanged="dgLog_Paged"
AutoGenerateColumns="False"
AllowSorting="true"
OnSortCommand="dgLog_Sort"
OnEditCommand="dgLog_Edit"
OnCancelCommand="dgLog_Cancel"
OnUpdateCommand="dgLog_Update"
OnDeleteCommand="dgLog_Delete"
DataKeyField="DialledNum"
OnItemDataBound="dgLog_ItemDataBound"
ShowFooter="true"
FooterStyle-Font-Bold="true"
FooterStyle-BackColor="#FF3333"
EditItemStyle-BackColor="#00CCFF">

<Columns>
<asp:BoundColumn DataField="DialledNum"
HeaderText="DialledNum" SortExpression="DialledNum" ReadOnly="true" />

<asp:TemplateColumn HeaderText="RSValue"
ItemStyle-Width="44px">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "RSValue") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtRSValue" runat="server"
width="30px" MaxLength="1" Font-Name="arial" Font-Size="8pt"
ToolTip="Enter RSValue"
Text='<%# DataBinder.Eval(Container.DataItem,
"RSValue") %>' />
<asp:requiredfieldvalidator ID="valRSValue"
ControlToValidate="txtRSValue" ErrorMessage="Please enter an RSValue"
Display="Dynamic"
runat="server">*</asp:requiredfieldvalidator>
<asp:RegularExpressionValidator id="valRSValueRegEx"
ControlToValidate="txtRSValue" ErrorMessage="Please enter a valid
RSValue" ValidationExpression="^\d$" Display="Dynamic"
runat="server">*</asp:RegularExpressionValidator>
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="DNXLate"
ItemStyle-Width="50px">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "DNXLate") %>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox id="chkDNXLate" Font-Name="arial"
Font-Size="8pt" runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="DCUG" ItemStyle-Width="79px">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "DCUG") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDCUG" runat="server" width="65px"
MaxLength="10" Font-Name="arial" Font-Size="8pt" ToolTip="Enter DCUG"
Text='<%# DataBinder.Eval(Container.DataItem,
"DCUG") %>' />
<asp:requiredfieldvalidator ID="valDCUG"
ControlToValidate="txtDCUG" ErrorMessage="Please enter a DCUG"
runat="server">*</asp:requiredfieldvalidator>
<asp:RegularExpressionValidator id="valDCUGRegEx"
ErrorMessage="Please enter a valid DCUG"
ControlToValidate="txtDCUG"
ValidationExpression="^\d{1,10}$"
Display="Static"
runat="server">
*
</asp:RegularExpressionValidator>
<asp:customvalidator ID="valCustom" runat="server"
ForeColor="#FFFFFF"
ControlToValidate="txtDCUG" OnServerValidate="Validate_DCUG"
Display="None" InitialValue="" ErrorMessage="Invalid
DCUG"></asp:customvalidator>
</EditItemTemplate>
</asp:TemplateColumn>


<asp:TemplateColumn HeaderText="CallType">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "CallType") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" id="lstCallTypes"
Font-Name="arial" Font-Size="8pt"
DataValueField="CallType"
DataTextField="CallType"
DataSource='<%# GetCallTypes() %>'
/>
</EditItemTemplate>
</asp:TemplateColumn>

<asp:BoundColumn DataField="StripDigits"
HeaderText="StripDigits" SortExpression="StripDigits" ReadOnly="true"/>
<asp:EditCommandColumn EditText="Edit"
ButtonType="LinkButton"
UpdateText="Update"
CancelText="Cancel"/>
<asp:ButtonColumn ButtonType="LinkButton" Text="Delete"
CommandName="Delete" />

<asp:TemplateColumn HeaderText="Flag">
<ItemTemplate>
<img src="images/CTRSPAIN.ICO" />
</ItemTemplate>
</asp:TemplateColumn>

</Columns>

<PagerStyle
Mode="NumericPages"
HorizontalAlign="Left"
ForeColor="#00015E"
BackColor="#dcdcdc"
NextPageText="Next"
PrevPageText="Previous" />

</asp:DataGrid>
</div>

<BR>
<asp:dropdownlist ID="ddlPageSize" ForeColor="#00015E"
Font-Name="verdana" runat="server">
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="10" Selected>10</asp:ListItem>
<asp:ListItem Value="15">15</asp:ListItem>
<asp:ListItem Value="20">20</asp:ListItem>
<asp:ListItem Value="25">25</asp:ListItem>
<asp:ListItem Value="50" >50</asp:ListItem>
<asp:ListItem Value="100">100</asp:ListItem>
</asp:DropDownList>

<asp:button ID="btnRepage" runat="server" Text="Change
Pagesize"
BackColor="#CCCCCC" ForeColor="#000000" Font-Bold="true"
BorderStyle="Ridge" Width="140px" Font-Name="Verdana"
Font-Size="10" Enabled="true" onClick="dgLog_Repage" />
<asp:button ID="btnRefreshData" runat="server" Text="Refresh
Data"
BackColor="#CCCCCC" ForeColor="#000000" Font-Bold="true"
BorderStyle="Ridge" Width="140px" Font-Name="Verdana"
Font-Size="10" Enabled="true" onClick="btnRefreshData_Click"
/>
<BR><BR>
<asp:ValidationSummary ID="valSum" runat="server"
DisplayMode="List"
Font-Name="verdana"
Font-Size="10"
Font-Bold="true"
ForeColor="#FF0000"
/>


</form>
</body>
</html>
 
Back
Top