FormView CheckBox 应使用账单信息填写运输信息
远离 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这一行:
应该是:
WebControl 的
ToString()
输出将是类型名称。This line:
Should be:
The
ToString()
output of a WebControl will be the type name.使用 :
Use :