You can do this by using jquery also :
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#gender').change(function(){
var value = $(this).val();
if(value == 1 || value == 0)
{
$('.pregnencyDiv').hide();
}
else
{
$('.pregnencyDiv').show();
}
});
});
</script>
<style>
.pregnencyDiv
{
display : none;
}
</style>
<div>
<select id="gender">
<option value='0'>--Select--</option>
<option value='1'>Male</option>
<option value='2'>Female</option>
</select>
<br>
<div class="pregnencyDiv">
Pregnancy count <input type='text' id='txtCount' name='txtCount' />
<div>
</div>
[Edit]
It is always good to avoid unnecessary server round trip. but if you need it in from server side here you go :
<div>
<asp:DropDownList ID="dropDownGender" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropDownGender_SelectedIndexChanged">
<asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
<asp:ListItem Value="1" Text="Male"></asp:ListItem>
<asp:ListItem Value="2" Text="Female"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtCount" runat="server" Enabled="false"></asp:TextBox>
</div>
then create
OnSelectedIndexChanged
event in your code behind page :
protected void dropDownGender_SelectedIndexChanged(Object sender, EventArgs e)
{
var value = Convert.ToInt32(dropDownGender.SelectedValue);
if (value == 0 || value == 1)
{
txtCount.Enabled= false;
}
else
{
txtCount.Enabled= true;
}
}
Hope it helps you. :)