日期:2014-05-17  浏览次数:20598 次

gridview中dropdownlist与textbox联动的问题
我想实现的效果是,将ddladjustreason选为清零时,txtadjustreason的enable改为false,请问在
ddladjustreason_TextChanged里应该怎么取到txtadjustreason?

<asp:TemplateField HeaderText="调整原因" >
  <ItemStyle HorizontalAlign="Center" />
  <ItemTemplate>
  <asp:DropDownList ID="ddladjustreason" runat="server" OnTextChanged="ddladjustreason_TextChanged" AutoPostBack="True">
  <asp:ListItem Value="0">其他</asp:ListItem>
  <asp:ListItem Value="1">清零</asp:ListItem>
  </asp:DropDownList>
  </ItemTemplate>
</asp:TemplateField>
  <asp:TemplateField HeaderText="调整原因说明">
  <EditItemTemplate>
  <asp:TextBox ID="txtadjustreason" runat="server" Text="" Width="50px"></asp:TextBox></asp:TextBox>
  </EditItemTemplate>
</asp:TemplateField>


  protected void ddladjustreason_TextChanged(object sender, EventArgs e)
  {
   
  if ( ddladjustreason.SelectedItem.Value == "1")
  {
  txtadjustreason-xxxxx.enable= false;//要取到txtadjustreason,还要判断是第几行的txtadjustreason
  }

  }

------解决方案--------------------
DropDownList ddladjustreason = (DropDownList)sender;
GridViewRow gvr = (GridViewRow)ddladjustreason.NamingContainer;
TextBox txtadjustreaon = (TextBox)gvr.FindControl("txtadjustreaon");


if (ddladjustreason.SelectedItem.Value == "1")
{
txtadjustreaon.Enabled = false;
}