dropdownlist SelectedIndexChanged事件更改其他文本框的值

时间:2012-03-26 22:59:35

标签: c# asp.net drop-down-menu

我有两个下拉列表和两个带有日历弹出扩展器的txtbox,每当我选择与第一个项目不同的项目时,此代码应将texbox填充到当前日期,我的下拉列表中选择了austoposbabk属性,并且位于更新面板,当我选择和项目时,它将两个文本框重置为仅重新选择SelectedIndexChanged上的文本框

例如,我只需要将默认日期设置为下拉列表中的标签selectedIndexChanged

txtScanner_SelectedIndexChanged

只会将txtscanDate字段设置为当前日期,,, 并在两个文本框中设置日期。

感谢您的帮助。对不起,我的英语不是很好。

<asp:DropDownList ID="txtPreppin" runat="server" CssClass="padding-input" 
 AutoPostBack="True" onselectedindexchanged="txtPreppin_SelectedIndexChanged">
  <asp:ListItem Text="-Select-" Value=''>-Select-</asp:ListItem>
  <asp:ListItem>Acevedo, Noe</asp:ListItem>
</asp:DropDownList>
<br />
<label for="recordtype">Date:</label>
<asp:TextBox ID="txtprepDate" runat="server" Enabled="False" ReadOnly="True"></asp:TextBox>
 <asp:CalendarExtender ID="txtprepDate_CalendarExtender" runat="server"
  Enabled="True" TargetControlID="txtprepDate" Format="MM/dd/yyyy">
</asp:CalendarExtender>                 

</td>
<td style="width: 306px">
<label for="recordtype">Scanner:</label>
<asp:DropDownList ID="txtScanner" runat="server" CssClass="padding-input" 
  AutoPostBack="True" onselectedindexchanged="txtScanner_SelectedIndexChanged">
 <asp:ListItem Text="-Select-" Value=''>-Select-</asp:ListItem>
 <asp:ListItem>Bueno, Nancy</asp:ListItem>
 </asp:DropDownList>

 <label for="recordtype">Date:</label>
 <br />
 <asp:TextBox ID="txtScanDate" runat="server" Enabled="False" ReadOnly="True"></asp:TextBox>
 <asp:CalendarExtender ID="txtScanDate_CalendarExtender" runat="server"
  Enabled="True" TargetControlID="txtScanDate" Format="MM/dd/yyyy">
 </asp:CalendarExtender>


protected void txtScanner_SelectedIndexChanged(object sender, EventArgs e)
{
 if (Page.IsPostBack)
 {
  if (txtScanner.SelectedItem.Text != null)
  {
    txtScanDate.Enabled = true;
    txtScanDate.ReadOnly = false;
    txtScanDate.Text = DateTime.Today.ToString("MM/dd/yyy");
  }
  else
  {
    txtScanDate.Enabled = false;
    txtScanDate.ReadOnly = true;
  }
 }
}

protected void txtPreppin_SelectedIndexChanged(object sender, EventArgs e) { if (Page.IsPostBack) { if (txtPreppin.SelectedItem.Text != null) { txtprepDate.Enabled = true; txtprepDate.ReadOnly = false; txtprepDate.Text = DateTime.Today.ToString("MM/dd/yyy"); } else { txtprepDate.Enabled = false; txtprepDate.ReadOnly = true; } } }

1 个答案:

答案 0 :(得分:0)

我发现了我的问题,我在主页面上启用了ViewState enabled = false,我很难找到这个,因为我继承的页面没有显示它被禁用,但是这导致了文本框丢失值的问题在postback.Thanks