4

顧客に関するレコードまたは情報を表示するためのボタンがあります。必要な情報をすべて提供した顧客を選択すると、その特定の顧客に関する情報が適切に表示されることに気付きました。別の顧客を表示しようとすると、その際、この特定の顧客の欠落しているフィールドは以前の顧客情報に置き換えられます。つまり、顧客情報を表示する前にテキストボックスをクリアする方法が必要です。情報。

public void ShowCustomerInformationCat1()
{
    if (customer.cCustomerType != null)
    {
        ModifyCustomerByCategoryddlCustomerType.SelectedIndex = ModifyCustomerByCategoryddlCustomerType.Items.IndexOf(ModifyCustomerByCategoryddlCustomerType.Items.FindByText(customer.cCustomerType.Trim()));
        ModifyCustomerByCategoryddlNewCustomerType.SelectedIndex = ModifyCustomerByCategoryddlNewCustomerType.Items.IndexOf(ModifyCustomerByCategoryddlNewCustomerType.Items.FindByText(customer.cCustomerType.Trim()));
    }
    if (customer.cInitial != null)
    {
        ModifyCustomerByCategoryddlInitial.SelectedIndex = ModifyCustomerByCategoryddlInitial.Items.IndexOf(ModifyCustomerByCategoryddlInitial.Items.FindByText(customer.cInitial.Trim()));
        ModifyCustomerByCategoryddlNewInitial.SelectedIndex = ModifyCustomerByCategoryddlNewInitial.Items.IndexOf(ModifyCustomerByCategoryddlNewInitial.Items.FindByText(customer.cInitial.Trim()));
    }
    if (customer.cGender != null)
    {
        ModifyCustomerByCategoryddlGender.SelectedIndex = ModifyCustomerByCategoryddlGender.Items.IndexOf(ModifyCustomerByCategoryddlGender.Items.FindByText(customer.cGender.Trim()));
        ModifyCustomerByCategoryddlNewGender.SelectedIndex = ModifyCustomerByCategoryddlNewGender.Items.IndexOf(ModifyCustomerByCategoryddlNewGender.Items.FindByText(customer.cGender.Trim()));
    }
    if (customer.cCountry != null)
    {
        ModifyCustomerByCategoryddlCountry.SelectedIndex = ModifyCustomerByCategoryddlCountry.Items.IndexOf(ModifyCustomerByCategoryddlCountry.Items.FindByText(customer.cCountry.Trim()));
        ModifyCustomerByCategoryddlNewCountry.SelectedIndex = ModifyCustomerByCategoryddlNewCountry.Items.IndexOf(ModifyCustomerByCategoryddlNewCountry.Items.FindByText(customer.cCountry.Trim()));
    }
}

textbox をクリアする方法を誰かに提案してもらえますか。個別にクリアしたくありません。提案をありがとう。

4

9 に答える 9

11
foreach (var item in Page.Controls)
{
    if (item is TextBox)
    {
        ((TextBox)item).Text = "";
    }
}
于 2012-06-04T11:59:39.517 に答える
2

このようにしてみてください。

foreach (var obj in Page.Controls.OfType<TextBox>())
{
   obj.Text="";
}
于 2012-06-04T12:03:22.650 に答える
2

これを試して:

Control myForm = Page.FindControl("Form1.aspx"); 
foreach (Control ctl in myForm.Controls) 
if (ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")) 
((TextBox)ctl).Text = ""; 
于 2012-06-04T12:03:23.190 に答える
1

私のシナリオでは、grdDetails という名前のグリッド コントロールにある特定の texbox(s) をクリアしたかっただけです。wpfでfw 4.0を使用する

foreach (var item in grdDetails.Children)
{
    if (item is TextBox)
    {
        ((TextBox)item).Text = "";
    }
}
于 2015-01-12T15:10:23.287 に答える
0
private void  function ClearSection()
{
    foreach (Control cntrl in Page.Controls)
    {
        if (cntrl is TextBox)
        {
            ((TextBox)cntrl).Text = "";
        }
    }
}
于 2013-03-02T08:38:33.600 に答える
0

非常に多くのコード行を使用する代わりに。テキスト ボックスの値を null プロパティに設定するだけで、1 つのコードで解決できます。

ここを参照

protected void btnSubmit_Click(object sender, EventArgs e)
{
    DataTable dt;
    USignUp USignUp = new USignUp();
    DateTime DOB;

    try
    {
        if (chkAccept.Checked == true)
        {
            DOB = Convert.ToDateTime(txtDOB.Text);
            int UserTypeId = 1;
            USignUp.SignUp_Insert(txtEmail.Text, txtPwd.Text, txtUFName.Text, txtULName.Text, txtCInfo.Text,
            DOB, UserTypeId);
            txtEmail.Text = "";
            txtPwd.Text = "";

            txtUFName.Text = "";
            txtULName.Text = "";
            txtCInfo.Text = "";
            txtCnfrEmail.Text = "";
            txtDOB.Text = "";
            txtCnfrmPwd.Text = "";
        }
        else
        {
            lblMessage.Visible = true;
            lblMessage.Text = "Please accept the terms and conditions";
            //Response.Write("<script LANGUAGE='JavaScript' >alert('Please select Checkbox');document.location='" + ResolveClientUrl("~/SignUp.aspx") + "';</script>");
        }
    }
    catch
    {
    }
}//It works.You can Know more on this by clicking to http://transinntech.com/
于 2013-09-28T11:35:32.140 に答える
0
protected void Button1_Click(object sender, EventArgs e)
{
    ClearSection();
    //Rest of your code
}

private void  function ClearSection()
{
    foreach (Control cntrl in Page.Controls)
    {
        if (cntrl is TextBox)
        {
            ((TextBox)cntrl).Text = "";
        }
    }
}
于 2012-06-04T12:04:03.757 に答える