ASP.NET GridView中的下拉列表Javascript验证 [英] Dropdownlist Javascript Validation In ASP.NET GridView

查看:54
本文介绍了ASP.NET GridView中的下拉列表Javascript验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个带有{txt_prodname,txt_type,txt_pages,txt_copies}的网格//这里txt_type是我的下拉列表.

现在我的要求是

1.在关注我的下拉菜单中,我需要选择默认值"SelectedIndex = 1"而不是"0".

因此我将js用作



I have an Grid with {txt_prodname,txt_type,txt_pages,txt_copies} //here txt_type is my Dropdown list.

Now my requirement is

1. While focus on my dropdown i need to select an default value of "SelectedIndex=1" not "0".

hence i use js as

function selectOneside(val) { //here val is my dropdown ID
var Dval = val.selectedIndex;
if (Dval == "0") {
    val.selectedIndex=1;
}
}


我在网格内的下拉菜单就像..


My dropdown inside grid is like..

<ItemTemplate>
                    <asp:DropDownList ID="txt_type" runat="server" AutoPostBack="true" onfocus="selectOneside(this);" onselectedindexchanged="txt_type_SelectedIndexChanged">
                        <asp:ListItem Value="0">--Select Type--</asp:ListItem>
                    <asp:ListItem Value="1">One Side</asp:ListItem>
                    <asp:ListItem Value="2">Diff Front &amp; Back</asp:ListItem>
                    <asp:ListItem Value="3">Same Front &amp; Back</asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>


直到工作正常,但是当我再次转到下一行时,它又更改了,而无需输入txt_prodname

因此,我将onblur事件用于网格内的txt_prodname作为...


Till that works fine, but while i go to the next row again its changed, without enter txt_prodname

Hence i use onblur event for my txt_prodname inside grid as...

<ItemTemplate>
                    <asp:TextBox ID="txt_prodname" runat="server" Width="110px" OnTextChanged="txt_prodname_TextChanged" CssClass="autocompleteTXT"></asp:TextBox>
                </ItemTemplate>


我的js是...


My js is...

function prodname(txtval,ddlval) {
    var Dval = txtval.value;
    if (Dval == "") {
        ddlval.selectedIndex = 0;
        txtval.focus();
    }
}


我从服务器端将此模糊事件绑定为


I bind this blur event from my server side as

txtprodname.Attributes.Add("onblur", "javascript : prodname(" + txtprodname.ClientID + "," + txttype.ClientID + ")");


正如我在js(prodname)中提到的那样,我专注于我的文本框,但是...
问题是当txt_prodname为空时,我的下拉列表无法恢复为"SelectedIndex = 0"

聚焦和模糊游戏在我的生活中:(

请帮帮我...


As i mentioned in js(prodname) i got focus to my textbox but...
Problem is my dropdown not getback to "SelectedIndex=0" when txt_prodname is empty

focus and Blur Play in my life :(

Please help me out...

推荐答案

一种不同的思维方式让我解决了这个问题.
我已将JS函数更改为...

A different way of thinking make me solve this....

I have changed my JS function as...

function selectOneside(val) {
    var Dval = val.selectedIndex;
    var row = val.parentNode.parentNode;
    var rowIndex = row.rowIndex;

    rowIndex = rowIndex + 1;

    var newId = "";
    if (rowIndex.toString().length == 1) {
        newId = "0" + rowIndex.toString();
    }
    else {
        newId = rowIndex.toString();
    }

    var txt = document.getElementById("ctl00_Adminmaster_Grid_job_ctl" + newId + "_txt_prodname").value;

if (Dval == "0" && txt != "") {
    val.selectedIndex = 1;
}

}


这篇关于ASP.NET GridView中的下拉列表Javascript验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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