如果任何Gridview文本框为空,则发出警报。 [英] Giving alert if any of the Gridview textbox is empty.
本文介绍了如果任何Gridview文本框为空,则发出警报。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在每行的Gridview中都有文本框,如果任何文本框在保存按钮单击时包含空值,我必须发出警告,如果超出gridview,则保存按钮。
我已按以下方式完成。
I have Textboxs in Gridview in each row i have to give the alert if any of Textbox will contain null values on save button click, save button if out of the gridview .
I have done in the following manner.
function validate() {
var flag = true;
var gridview = document.getElementById('<%=grdprescript.ClientID %>'); //GridView1 is the id of ur gridview.
var texts = new Array();
for (var i = 0; i < texts.length; i++) {
if (texts.items(i).value == '') //If dropdown has no selected value
{
flag = false;
break; //break the loop as there is no need to check further.
}
}
if (!flag) {
alert('Please Enter Date in each text');
}
return flag;
}
请事先帮助我的朋友。
Please help me friends thank in advance.
推荐答案
逻辑
On 保存按钮点击事件 ...
- 循环通过
GridViewRows
- 在
中查找特定控件(
TextBox
) GridViewRow- 检查其值是否为空
- 在每行上显示一个标签
TextBox
value为空(显示每行的警报不是一个好主意)
Logic
On Save Button Click Event...
- Loop through the
GridViewRows
- Find the particular Control (
TextBox
) inside theGridViewRow
- Check is its value is null
- Show one lable on each row saying
TextBox
value is null (showing alert for each row is not a good idea)
在保存按钮中单击确认
Try this in Save button click
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.Cells[0].Value == null)
{
MessageBox.Show("Your Message here");
}
}
单元格[0]是网格第一列,您可以使用任何列...
Cells[0] is grids first column you can use any column...
if(row.Cells [2] .ClientID.text.tostring()== 0 || row.Cells [3] .text.tostring()== 0 || row.Cells [1] .ClientID ==" 0")
{
alert();或者lblerrormsg.text =请输入日期;
}
// 3将用于下拉列表
if (row.Cells[2].ClientID.text.tostring() == 0 || row.Cells[3].text.tostring()== 0 || row.Cells[1].ClientID=="0")
{
alert(); or lblerrormsg.text=" please enter date";
}
// 3 will for dropdownlist
这篇关于如果任何Gridview文本框为空,则发出警报。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文