Creo haber llegado a la siguiente afirmación, pero alguién podría
confirmarla por favor (además de arrojar un poco de luz si es posible
a porque pasa esto).
Los controles que de forma "declarativa" (no de forma dinámica) se
agregan a una plantilla no mantienen su estado entre postbacks.
Esto surge porque tengo un combo con 2 posibles valores dentro del
HeaderTemplate de un FormView (control que "no" está enlazado a
datos), y al paginar siempre pierdo la selección del combo, volviendo
este a tener seleccionado siempre el primer valor disponible.
Sin embargo, veo que sí podría recuperar el valor desde
Request.Form.Item("FormView1$DropDownList1"), pero la gracia está
justa en que no tenga que currarme eso, no? Porque entonces tendría
que escribir código en Page_Load para seleccionar de forma manual el
valor seleccionado en el combo.
¿Esto es así siempre para controles "no" enlazados a datos y que estén
dentro de templates? (pregunta general).
Dejo el código por si ayuda.
Muchas gracias.
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="borrar.aspx.vb" Inherits="borrar" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:MSSConnectionString %>"
SelectCommand="SELECT * FROM [PaymentMethods]"></
asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server"
AllowPaging="True"
DataKeyNames="CompanyID,PaymentMethodID"
DataSourceID="SqlDataSource1">
<EditItemTemplate>
CompanyID:
<asp:Label ID="CompanyIDLabel1" runat="server"
Text='<%# Eval("CompanyID") %>' />
<br />
PaymentMethodID:
<asp:Label ID="PaymentMethodIDLabel1" runat="server"
Text='<%# Eval("PaymentMethodID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%#
Bind("Name") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True"
CommandName="Update" Text="Actualizar" />
<asp:LinkButton ID="UpdateCancelButton"
runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancelar" />
</EditItemTemplate>
<InsertItemTemplate>
CompanyID:
<asp:TextBox ID="CompanyIDTextBox" runat="server"
Text='<%# Bind("CompanyID") %>' />
<br />
PaymentMethodID:
<asp:TextBox ID="PaymentMethodIDTextBox"
runat="server"
Text='<%# Bind("PaymentMethodID") %>' />
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%#
Bind("Name") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True"
CommandName="Insert" Text="Insertar" />
<asp:LinkButton ID="InsertCancelButton"
runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancelar" />
</InsertItemTemplate>
<ItemTemplate>
CompanyID:
<asp:Label ID="CompanyIDLabel" runat="server" Text='<
%# Eval("CompanyID") %>' />
<br />
PaymentMethodID:
<asp:Label ID="PaymentMethodIDLabel" runat="server"
Text='<%# Eval("PaymentMethodID") %>' />
<br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%#
Bind("Name") %>' />
<br />
</ItemTemplate>
<HeaderTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="11">1</asp:ListItem>
<asp:ListItem Value="22">2</asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
"Templates decrease the need for you to create dynamic controls
manually because they let you declaratively define a "template" by
which controls will be created dynamically for you."
Digo yo...
Un saludo y gracias.