1.First Open a new Webapplication and name that web application as Sample.aspx.
2.In the default.aspx,add a GridView and bind some values to it.While editing,you have to validate the textbox.
3.I have used validation for the textbox containing discount.
Below is the design code cum server side coding
HTML Page:
<asp:GridView ID="gvGrid" AllowPaging="True"
runat="server" AutoGenerateColumns="False" HorizontalAlign="Center"
RowStyle-HorizontalAlign="Justify" AlternatingRowStyle-BackColor="#F2F2F2"
BorderColor="Red" RowStyle-BackColor="White" RowStyle-Height="25px"
RowStyle-BorderColor="Black" RowStyle-BorderWidth="1px" AlternatingRowStyle-Height="25px"
EnableTheming="True" EmptyDataText="No Record(s) are found." Width="100%"
onpageindexchanging="gvDisplayData_PageIndexChanging"
onrowdeleting="gvDisplayData_RowDeleting"
onrowediting="gvDisplayData_RowEditing"
onrowupdating="gvDisplayData_RowUpdating"
onrowcancelingedit="gvDisplayData_RowCancelingEdit" >
<Columns>
<asp:TemplateField HeaderText="Discount">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblDiscount" runat="server" Text=''> </asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="gvtxtDiscount" runat="server" Width="50px" MaxLength="3" onblur="javascript:return gvCheckDiscount();"></asp:TextBox>
<cc1:FilteredTextBoxExtender runat="server" ID="ftbegvtxtDiscount" TargetControlID="gvtxtDiscount"
FilterType="Numbers" FilterMode="ValidChars">
</cc1:FilteredTextBoxExtender>
</EditItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
JavaScript
function gvCheckDiscount() {
var retValue=1;
if (navigator.appName=="Microsoft Internet Explorer")
{
retValue = 0;
}
var gridviewID = '';
var gridview = document.getElementById(gridviewID);
if (gridview != null && gridview.rows != null)
{
for (i = 1; i < gridview.rows.length; i++)
{ var DiscountValue = gridview.rows[i].cells[3].childNodes[retValue].value; var ddlType = gridview.rows[i].cells[2].childNodes[retValue].value; if (ddlType == "0") { if (DiscountValue == "") { alert('Please enter the value'); gridview.rows[i].cells[3].childNodes[retValue].focus(); return false; } if (DiscountValue == "0") { alert('Should not allow the zeros'); gridview.rows[i].cells[3].childNodes[retValue].value = ""; gridview.rows[i].cells[3].childNodes[retValue].focus(); return false; } if (DiscountValue > 100) {
alert('Discount should be less than or equal to 100');
gridview.rows[i].cells[3].childNodes[retValue].value = "";
gridview.rows[i].cells[3].childNodes[retValue].focus();
return false;
}
}
No comments:
Post a Comment