远离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;
答案 0 :(得分:2)
这一行:
ShippingFirst.Text = BillingFirst.ToString();
应该是:
ShippingFirst.Text = BillingFirst.Text;
WebControl的ToString()
输出将是类型名称。
答案 1 :(得分:1)
使用:
ShippingFirst.Text = BillingFirst.Text;