Karthik_Mahalingam
пробовать
ASP / HTML
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="ID" DataField="ID" />
<asp:BoundField HeaderText="Name" DataField="Name" />
<asp:TemplateField HeaderText="Value">
<ItemTemplate>
<asp:TextBox CssClass="TextField" ID="txt" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnSubmit" Text="Save" runat="server" OnClientClick="return ValidateGrid();" />
Язык JavaScriptfunction ValidateGrid() {
var grid = document.getElementById('<%= gv.ClientID%>');
var length = grid.rows.length;
if (length > 1)
for (var i = 1; i < length; i++) {
var row = grid.rows[i];
var textbox = row.getElementsByClassName('TextField')[0];
var value = textbox.value;
if (value.match(/[^0-9]/g, '')) {
alert('Please enter valid data');
textbox.focus();
return false;
}
return true;
}
}
С фоновым кодомprotected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Value");
dt.Rows.Add(1, "karthik", "");
dt.Rows.Add(2, "prasanth", "");
dt.Rows.Add(2, "sachin", "");
dt.Rows.Add(2, "sehwag ", "");
gv.DataSource = dt;
gv.DataBind();
}
}