Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/07/2005, 17:12
Avatar de RootK
RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 23 años, 1 mes
Puntos: 50
para estos casos prefiero hacerlo con javascript para evitar hacer la peticion al server.. aunque es un poco mas de trabajo pero vale la pena para el cliente..

Supongamos que tienes un DDL y tus textbox de ésta forma:

Cita:
<asp:DropDownList id="ddlTimers" runat="server">
<asp:ListItem Value="0">Seleccione uno</asp:ListItem>
<asp:ListItem Value="1">mensual</asp:ListItem>
<asp:ListItem Value="2">semestral</asp:ListItem>
<asp:ListItem Value="3">anual</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
En tu codebehind.. le cargas el evento a tu DDL para hacer la validacion...

Cita:
ddlTimers.Attributes.Add("onchange", "addDate(this)")
Y lo interesante sería aqui en tu javascript..
que sería:

Cita:
<script language=javascript>
function addDate(obj)
{
var iValue = parseInt(obj.options[obj.selectedIndex].value);
switch (iValue)
{
case 1: //semestral
iValue = 1;
break;
case 2:
iValue = 3 //trimestral
break;
case 3:
iValue = 12 //anual
break;
}
var txt = document.getElementById("TextBox1");
var arrDate = txt.value.split("/") //separo la fecha

var iYear = arrDate[2]
var iMonth = arrDate[1];
var iDay = arrDate[0];

var dDate = new Date(iYear,iMonth,iDay);
dDate.setMonth(dDate.getMonth() + iValue); //le sumo los meses dependiendo de la seleccion
iYear = dDate.getFullYear();
iMonth = dDate.getMonth();
iDay = dDate.getDay();

txt = document.getElementById("TextBox2"); //obtengo el textbox para el resultado
txt.value = iDay.toString() + "/" + iMonth.toString() + "/" + iYear.toString()
}
</script>
hice éste código rápido.. obviamente ya tu le pondrías las validaciones correspondientes... pero esa es la idea..

Espero que te sirva..

Salu2