如何在.NET中单击Generic中清除多个TextBox,单选按钮,复选框值 [英] How to clear a Multiple TextBox, Radio Button ,Check Box values in a single click Generic in .NET

查看:110
本文介绍了如何在.NET中单击Generic中清除多个TextBox,单选按钮,复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除多个文本框,单选按钮,复选框值,只需单击一下Asp.NET中的Generic和C#

How to clear a Multiple TextBox, Radio Button, Check Box values in a single click Generic in Asp.NET and C#

推荐答案

我有这个方法,我在按钮点击事件上调用此方法来清除表单数据



这是我的方法

I have this method and i call this method on a button click event to clear the forms data

Here is my method
public static void ClearFields(ControlCollection pageControls)
    {
        foreach (Control contl in pageControls)
        {
            string strCntName = (contl.GetType()).Name;

            switch (strCntName)
            {
                case "TextBox":
                    TextBox tbSource = (TextBox)contl;
                    tbSource.Text = "";
                    break;
                case "RadioButtonList":
                    RadioButtonList rblSource = (RadioButtonList)contl;
                    rblSource.SelectedIndex = -1;
                    break;
                case "DropDownList":
                    DropDownList ddlSource = (DropDownList)contl;
                    ddlSource.SelectedIndex = -1;
                    break;
                case "ListBox":
                    ListBox lbsource = (ListBox)contl;
                    lbsource.SelectedIndex = -1;
                    break;
            }
            ClearFields(contl.Controls);
        }
    }







点击按钮即可调用此方法follow \




Call this method on a button click such as follows\

protected void btn_cancel_Click(object sender, EventArgs e)
    {
        ClearFields(Form.Controls);
    }


link [ ]



链接 [ ]



参考这些链接
link[]

link[]

refer these links


您好b $ b

如果您想清除某些控件值,请转到客户端脚本。

我给出了符合你要求的虚拟场景。



Hi
If you want to clear certain controls value then go for Client Side Scripts.
I have given a dummy scenario which matches your requirements.

<asp:CheckBox ID="CheckBox1" Text="Check Item" Checked="true"  runat="server" />
<asp:RadioButton ID="RadioButton1" Text="Radio Item" Checked="true" runat="server" />
<asp:TextBox ID="TextBox1"   runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ClearAll()" />





和脚本是





and the script is

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    function ClearAll() {


这篇关于如何在.NET中单击Generic中清除多个TextBox,单选按钮,复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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