如何使用相同的GridView RSS烧制的“Onclientsideselectedindexchanged”一个radcombobox控件的JavaScript函数发现文本框在GridView控件 [英] How to find textbox in GridView using javascript function fired on “Onclientsideselectedindexchanged” of a radcombobox in same GridView RSS

查看:247
本文介绍了如何使用相同的GridView RSS烧制的“Onclientsideselectedindexchanged”一个radcombobox控件的JavaScript函数发现文本框在GridView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个控件的文本框,并在GridView中的ItemTemplate一个radcombobox控件。当radcombobox控件的事件onclientsideselectedindexchanges被激发我想做的是。我想显示/隐藏与JavaScript客户端的文本框。

I have two controls a textbox and a radcombobox in ItemTemplate of a GridView. What I want to do is when the event onclientsideselectedindexchanges of radcombobox is fired. I want to show/Hide the textbox on client side with javascript.

这个基本目的是为了避免回发,以显示其将数据绑定到数据库中的文本框。

Basic purpose of this is to avoid post back to show the textbox which will be databound to database.

如果它是不可能在客户端做,那么请建议在服务器端有些另类。

If it is not possible to do on the client-side, then please suggest some alternative on server side.

推荐答案

在我的例子,我有一个模板领域的GridView和它包含一个下拉菜单和文本框。 onload事件JavaScript中的文本框的显示样式设置为无。
 设置在GridView的onrowdatabound事件下拉的onchange事件,并呼吁在此处设置文本框的显示风格您需要什么样的JavaScript函数。

In my example, I have a gridview with a template field and it contains a dropdown menu and a textbox. The onload event in javascript sets the display style of the textbox to "none". Set the onchange event of the dropdown in onrowdatabound event of the gridview and call the javascript function where you set the textbox display style to what you require.

在我的例子中,我显示文本框只有在下拉列表中选择指标为1。

In my example, I display the textbox only when the dropdown selected index is "1".

我所做的这一切在我的code - 是指这样的:
 GridView控件ID =GridView1

I have done all this in my code--refer to this: Gridview ID="GridView1"

<Columns>
    <asp:TemplateField HeaderText="Order Status">
        <ItemTemplate>
           <asp:DropDownList ID="ddlOrderStatus" runat="server" Width="104px" ToolTip="Select order status">
            </asp:DropDownList><br />
             <asp:TextBox ID="txtShipTrackNo" runat="server" 
      Width="100px" Text='<%# Eval("sct_order_docket_id") %>'></asp:TextBox>
</ItemTemplate>
    </asp:TemplateField>
</Columns>

<script type="text/javascript">
var TargetBaseControl = null;
window.onload = function() {
    try {
    //get target base control.
    TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
    for (var rowId = 1; rowId < TargetBaseControl.rows.length; ++rowId) {
    var txtShip = TargetBaseControl.rows[rowId].cells[0].getElementsByTagName("input")[0];
    txtShip.style.display = "none";
        }
    }
    catch (err) {
        TargetBaseControl = null;
    }
}

function selectCheck(rowid) 
{
     TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
     var ddlStatus = TargetBaseControl.rows[rowid].cells[0].getElementsByTagName("select")[0];
     var txtShip = TargetBaseControl.rows[rowid].cells[0].getElementsByTagName("input")[0];
     txtShip.style.display = "none";
     if (ddlStatus.selectedIndex == '1') {
         txtShip.style.display = "block";
     }         
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DropDownList ddlStatus = (DropDownList)e.Row.FindControl("ddlOrderStatus");
        string strFunc = string.Format("return selectCheck('{0}')", e.Row.RowIndex + 1);  
        ddlStatus.Attributes.Add("onchange", strFunc);
    }
}

这篇关于如何使用相同的GridView RSS烧制的“Onclientsideselectedindexchanged”一个radcombobox控件的JavaScript函数发现文本框在GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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