FormView CheckBox 应使用账单信息填写运输信息

发布于 2024-11-02 13:10:43 字数 1416 浏览 0 评论 0原文

远离 javascript,我尝试使用 Check_Clicked 事件处理程序来填充我的运输信息(如果与 FormView 中的账单信息相同)。这应该很简单,但我无法正确安装管道。

我正在遵循 http:// /msdn.microsoft.com/en-us/library/4s78d0k1%28v=vs.71%29.aspx#Y617 但想要使用我的 FormView 而不是 Form1。

选中该框时出现的值是 System.Web.UI.WebControls.TextBox

<asp:CheckBox id="SameCheckBox" AutoPostBack="True"
                    Text="Same as billing." TextAlign="Right"
                    OnCheckedChanged="Check_Clicked" runat="server"/>


 protected void Check_Clicked(Object sender, EventArgs e)
    {
        CheckBox SameCheckBox = (CheckBox)FormView1.FindControl("SameCheckBox");
        TextBox BillingFirst = (TextBox)FormView1.FindControl("BillingFirstNameTextBox");
        TextBox ShippingFirst = (TextBox)FormView1.FindControl("ShippingFirstNameTextBox");

        if (SameCheckBox.Checked)
        {    
            ShippingFirst.Text = BillingFirst.ToString();

        }
        else
            ShippingFirst = null;
    }

除了下面给我的解决方案之外,我还将添加其他人的启发;我遇到的另一个问题是 DropdownList 数据。这对我有用:

DropDownList BillingState = FormView1.Row.FindControl("BillingStateTextBox") as DropDownList;
DropDownList ShippingState = FormView1.Row.FindControl("ShippingStateTextBox")as DropDownList;
ShippingState.SelectedValue = BillingState.Text;

Staying away from javascript I endeavor to use Check_Clicked event handler to populate my Shipping info if same as Billing info in my FormView. This should be real simple but I have not been able to get the plumbing right.

I am following the example in http://msdn.microsoft.com/en-us/library/4s78d0k1%28v=vs.71%29.aspx#Y617 but would like to use my FormView instead of Form1.

The value that appears on checking the box is System.Web.UI.WebControls.TextBox

<asp:CheckBox id="SameCheckBox" AutoPostBack="True"
                    Text="Same as billing." TextAlign="Right"
                    OnCheckedChanged="Check_Clicked" runat="server"/>


 protected void Check_Clicked(Object sender, EventArgs e)
    {
        CheckBox SameCheckBox = (CheckBox)FormView1.FindControl("SameCheckBox");
        TextBox BillingFirst = (TextBox)FormView1.FindControl("BillingFirstNameTextBox");
        TextBox ShippingFirst = (TextBox)FormView1.FindControl("ShippingFirstNameTextBox");

        if (SameCheckBox.Checked)
        {    
            ShippingFirst.Text = BillingFirst.ToString();

        }
        else
            ShippingFirst = null;
    }

In addition to the solutions given to me below I will add for others edification; the other problem I had was DropdownList data. Here is what worked for me:

DropDownList BillingState = FormView1.Row.FindControl("BillingStateTextBox") as DropDownList;
DropDownList ShippingState = FormView1.Row.FindControl("ShippingStateTextBox")as DropDownList;
ShippingState.SelectedValue = BillingState.Text;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戴着白色围巾的女孩 2024-11-09 13:10:43

这一行:

ShippingFirst.Text = BillingFirst.ToString();

应该是:

ShippingFirst.Text = BillingFirst.Text;

WebControl 的 ToString() 输出将是类型名称。

This line:

ShippingFirst.Text = BillingFirst.ToString();

Should be:

ShippingFirst.Text = BillingFirst.Text;

The ToString() output of a WebControl will be the type name.

孤檠 2024-11-09 13:10:43

使用 :

ShippingFirst.Text = BillingFirst.Text;

Use :

ShippingFirst.Text = BillingFirst.Text;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文