gridview下拉列表如何验证gridview按钮点击? [英] how gridview dropdownlist validate on gridview button click ?

查看:92
本文介绍了gridview下拉列表如何验证gridview按钮点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview项目模板字段中有一个下拉列表控件,我想在按钮点击时对该控件进行操作,按钮也在gridview中。所以请告诉我任何验证方法javascript验证或服务器端验证

I have a dropdownlist control in gridview item template field and i want to valdate that control on button click ,button also in gridview . so please tell me any validation method either javascript validation or server side validation

推荐答案

<asp:TemplateField ItemStyle-VerticalAlign="Top">
    <ItemTemplate>
        <asp:dropdownList id="drp_item" runat="server"></asp:dropdownList>
    </ItemTemplate>
</asp:TemplateField>

<asp:TemplateField ItemStyle-VerticalAlign="Top">
    <ItemTemplate>
        <asp:LinkButton ID="btn_Add" ToolTip="ADD Product" OnClientClick="javascript:return Validate(this);" runat="server">
        </asp:LinkButton>
    </ItemTemplate>
</asp:TemplateField>




function Validate(ths,) {
    var Cntrl_Id = ths.id.split('_');
    var drp = Cntrl_Id[0] + '_' + Cntrl_Id[1] + '_dropdown';  // here dropdown is dropdwon name.
    if ((document.getElementById(drp).value == "")
    {
        alert("Please Enter the Strength.");
        return false;
    }
    return true;
}



在下面的函数中,它将传递实际的按钮名称,并且ths.id.split你可以找到你的下拉控件名称Cntrl_Id [0]可以取决于你的实际页面及其控件。 />


谢谢

Zubair


In below function ths will pass the actual button name and will ths.id.split you can find the your dropdown control name number of Cntrl_Id[0] can be depend on the you actual page and its control.

Thanks
Zubair


function ValidateGridView() {

    var grid = document.getElementById('<%=GridView.ClientId=%>);

    if (grid != null) {
   
            var TargetBaseControl = grid;

            //var TargetChildControl1 = "TxtGrNo";
            //get all the control of the type INPUT in the base control.
            var Inputs = TargetBaseControl.getElementsByTagName("input");

            for (var n = 0; n < Inputs.length; ++n) {
                if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkSelect', 0) >= 0) {
                    if (Inputs[n].checked) {
                        var RowId = (Inputs[n].parentNode.parentNode.parentNode).rowIndex;
                        var InpCtrls = grid.rows[RowId].getElementsByTagName('input');
                        for (var i = 0; i < InpCtrls.length; ++i) {
                            if (InpCtrls[i].id.indexOf('TxtGrNo', 0) >= 0 && InpCtrls[i].value == '') {
                                document.getElementById(InpCtrls[i].id).style.border = "1px solid red";
                                document.getElementById(InpCtrls[i].id).style.background = "#FFCECE";
                                document.getElementById(InpCtrls[i].id).focus();
                                alert('Plz Enter value in GRNumber...!');
                                return false;
                            }
			}
		}
	    }
	}

}





上面的代码用于验证GridView中的任何控件。

我已经在Gridview中通过查找Gridview中的所有输入控件实现了上面的复选框和文本框代码。 br />
同样可以用于gridview中的选择控件。



Above code is used to validate any controls inside GridView.
I have implemented above code for checkbox and textbox inside gridview by finding all input controls from Gridview.
Same you cand use for "Select" controls inside gridview.


你的Button是否在网格内?
Is your Button is inside the grid?


这篇关于gridview下拉列表如何验证gridview按钮点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆