在gridview内的文本框中应用验证 [英] Apply Validation in textbox inside of gridview
问题描述
嗨
i有一个网格视图..
i我正在使用此网格视图输入数据...
at start i am am显示3行
每行
有保存按钮以保存数据库中的当前行数据..
我想验证此文本框。 ..
但问题是如果我使用
服务器端验证,所以如果我只验证Textbox1 alphabate所以它的验证所有行的Textbox1..Becuase在所有行中重复相同的文本框...
如何在javascript中验证...如果它在gridview里面
Plse给出任何建议....
hi
i have one grid view..
i am using this grid view for enter the data...
at start i am show 3 row
in every row there are save button to save current row data in database..
I want to validate this textbox...
But problem is if i am using
server side validation so if i validate Textbox1 for only alphabate so its validate Textbox1 of all row..Becuase same textbox repeated in all row ...
How can i validate in javascript... if it is inside of gridview
Plse give any suggestion....
推荐答案
你好,
我为你的要求制作一些代码。试试看,如果你有兴趣,那就对它进行一些修改并使用它。
Hi,
I make some code for your requirement .Just try that If you interested then make some changes to that and use it.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script language ="javascript" >
function f1(tid) {
tid.innerText = ""
}
</script>
</head>
<body >
<form id="form1" runat="server">
<div>
<asp:datalist id="DataList1" runat="server" xmlns:asp="#unknown">
onitemcommand="DataList1_ItemCommand"
onitemdatabound="DataList1_ItemDataBound" >
<HeaderTemplate > <table>
</HeaderTemplate>
<itemtemplate>
<tr>
<td>
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
</td>
<td>
<asp:linkbutton id="LinkButton1" runat="server" commandname="save" commandargument="2">save</asp:linkbutton>
</td>
</tr>
</itemtemplate>
<footertemplate>
</footertemplate></table>
</asp:datalist>
</div>
</form>
</body>
</html>
文件背后的代码包含以下代码
The code behind file contains following code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<string> g = new List<string>();
g.Add("hjghj");
g.Add("hjghj");
g.Add("hjghj");
g.Add("hjghj");
g.Add("hjghj");
g.Add("hjghj");
g.Add("hjghj");
DataList1.DataSource = g;
DataList1.DataBind();
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "save")
{
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
TextBox rdblist = (TextBox )e.Item.FindControl("TextBox1");
LinkButton lblqid = (LinkButton)e.Item.FindControl("LinkButton1");
lblqid.OnClientClick = "f1("+rdblist.ClientID +")";
}
}
</string></string>
这里你要根据你的要求更改一些代码。
我希望你明白我写的是什么
所有最好的
Here you''ve to change some code according to your requirement.
I hope you understood What I write
All the Best
在asp:gridview中的列标记内使用这样的内容
Use like this inside of column tag in asp:gridview
< asp:templatefield headertext =TIN No. itemstyle-horizontalalign =中心xmlns:asp =#unknown>
< edititemtemplate>
< asp:textbox id =txttinrunat = servertext =<%#Eval(tin)%> />
< itemtemplate>
< asp:label id =lbltinrunat =servertext =< ;%#Eval(tin)%> />
< footertemplate>
< asp:textbox id =txttinrunat =server/ >
< asp:requiredfieldvalidator id =rfvtinrunat =server>
ControlToValidate =txttinText =*ValidationGroup =validaiton />
<asp:templatefield headertext="TIN No." itemstyle-horizontalalign="Center" xmlns:asp="#unknown">
<edititemtemplate>
<asp:textbox id="txttin" runat="server" text="<%#Eval("tin") %>" />
<itemtemplate>
<asp:label id="lbltin" runat="server" text="<%#Eval("tin") %>" />
<footertemplate>
<asp:textbox id="txttin" runat="server" />
<asp:requiredfieldvalidator id="rfvtin" runat="server">
ControlToValidate="txttin" Text="*" ValidationGroup="validaiton" />
这篇关于在gridview内的文本框中应用验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!