Your markup up is invalid. The markup editor underlines the error and if not fixed the Web Page will not compile. Please share working code when asking for assistance on the forums.
How to make readonly gridview footer template textbox calendar control
The TextBox has a ReadOnly attribute, the calendar extender has an enabled property (inherited from ExtenderControlBase) and the Image control has a Visible property (inherited from Control) .
You've provided no information as to how read only mode is entered. I can only guess how your logic is intended to function. The best I can do is show how to programmatically set server control properties.
How to validation numeric and decimal on keypress in another textbox for the same.
The TextBox control has a TextMode attribute which renders an HTML 5 inputs. Set the attribute to "Number". The user can only enter numeric values including the decimal character.
Demo code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewFooter.aspx.cs" Inherits="WebFormsDemo.Gridviews.GridViewFooter" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" ShowFooter="true" OnDataBound="gvCustomers_DataBound">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<FooterTemplate>
<asp:UpdatePanel runat="server" ID="Up_LeaveDetails" UpdateMode="Always">
<ContentTemplate>
<asp:DropDownList ID="ddlCustomers" Width="100px" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCustomers_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="txtOtherCustomers" Text="" runat="server" Visible="false"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCustomers" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<%# Eval("Country") %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DOB">
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<div>
<asp:TextBox ID="txtDOB" runat="server" Text=""></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDOB"
Format="MM/dd/yyyy" PopupButtonID="btnDate1"
PopupPosition="BottomRight" CssClass="cal_Theme1" ></ajaxToolkit:CalendarExtender>
<asp:ImageButton ID="btnDate1" ImageUrl="~/images/imgCalendar.png" Width="16" Height="16"
runat="server" />
</div>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PayAmount">
<ItemTemplate>
<%# Eval("PayAmount") %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPayAmount" runat="server" TextMode="Number"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Upload">
<ItemTemplate>
<%# Eval("FileName") %>
</ItemTemplate>
<FooterTemplate>
<asp:FileUpload ID="fuUpload" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Add" CommandName="Footer" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<tr>
<th scope="col">Customer Name</th>
<th scope="col">Name</th>
<th scope="col">Country</th>
<th scope="col">DOB</th>
<th scope="col">Upload</th>
<th scope="col"></th>
</tr>
<tr>
<td>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Always">
<ContentTemplate>
<asp:DropDownList ID="ddlCustomer" Width="100px" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCustomer_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="txtOtherCustomer" Text="" runat="server" Visible="false"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCustomer" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
<asp:TextBox ID="txtName" runat="server" /></td>
<td>
<asp:TextBox ID="txtCountry" runat="server" />
</td>
<td>
<asp:TextBox ID="txtDOB" CssClass="txtInput" runat="server" Text=""></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDOB"
Format="MM/dd/yyyy" PopupButtonID="btnDate1"
PopupPosition="BottomRight" CssClass="cal_Theme1"></ajaxToolkit:CalendarExtender>
<asp:ImageButton ID="btnDate1" ImageUrl="~/images/imgCalendar.png"
runat="server" />
</td>
<td>
<asp:TextBox ID="txtPayAmount" runat="server"></asp:TextBox>
<td></FooterTemplate>
<%--</asp:TemplateField>--%>
<td>
<asp:FileUpload ID="fuUpload" runat="server" />
</td>
</tr>
</EmptyDataTemplate>
</asp:GridView>
<table>
<tr>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Add" />
</td>
</tr>
</table>
</form>
<script>
</script>
</body>
</html>
Code behind
using AjaxControlToolkit;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebFormsDemo.Gridviews
{
public partial class GridViewFooter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
gvCustomers.DataSource = PopulateDataSource();
gvCustomers.DataBind();
}
}
protected List<ViewModel> PopulateDataSource()
{
return new List<ViewModel> {
new ViewModel() { CustomerName = "Les Paul", Country="USA", DOB=DateTime.Now.ToShortDateString(), Name="Les", PayAmount=123.45m, FileName="File1"},
new ViewModel() { CustomerName = "Leo Fender", Country="USA", DOB=DateTime.Now.ToShortDateString(), Name="Leo", PayAmount=678.90m, FileName="File1"}
};
}
protected void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void ddlCustomers_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Add(object sender, EventArgs e)
{
}
protected void gvCustomers_DataBound(object sender, EventArgs e)
{
GridView grid = (GridView)sender;
GridViewRow footerRow = grid.FooterRow;
//Set the DOB control to readonly
TextBox amount = (TextBox)footerRow.FindControl("txtDOB");
amount.ReadOnly = true;
//Disable the calendar
CalendarExtender calendar = (CalendarExtender)footerRow.FindControl("CalendarExtender1");
calendar.Enabled = false;
Image calendarImage = (Image)footerRow.FindControl("btnDate1");
calendarImage.Visible = false;
}
}
public class ViewModel
{
public string CustomerName { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public string DOB { get; set; }
public decimal PayAmount { get; set; }
public string FileName { get; set; }
}
}