2011-04-20 82 views
1

远离javascript我试图使用Check_Clicked事件处理程序填充我的运输信息,如果相同作为我的FormView中的帐单信息。这应该是很简单的,但我没有得到正确的管道。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; 

回答

2

这条线:

ShippingFirst.Text = BillingFirst.ToString(); 

应该是:

ShippingFirst.Text = BillingFirst.Text; 

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

+0

**哇** ...你们都快。并感谢您的教训。当然,我的formview现在是功能性的。 – 2011-04-20 17:55:40

+0

@Steve乐于帮助 - upvotes赞赏! – Marcie 2011-04-20 18:27:14

+0

@Marcle:我想我们值得我们的答案:D – 2011-04-20 18:34:14

1

用途:

ShippingFirst.Text = BillingFirst.Text; 
+0

哎呦,我有点太慢:) – Marcie 2011-04-20 17:45:56

+0

@Marice:你写了太多的信息.​​. – 2011-04-20 17:46:52

+0

也谢谢Akram。 – 2011-04-20 17:56:55