nostromo ha scritto:
postalo altrimenti è difficile capire cosa non và, comunque come ti dicevo se sospetti che parte del codice ti sollevi eccezione a designtime usa la proprietà che designmode per evitarlo
ciao marco
//aspx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="webcontrolLabelComboGenerico.ascx.cs" Inherits="webcontrolLabelComboGenerico" %>
<p style="text-align:left;margin:0px;padding:0px">
<asp:Label ID="Label1" runat="server" Text="Label">Seleziona un </asp:Label>
<br />
<asp:DropDownList EnableViewState="False" ID="DropDownList1" runat="server" DataSourceID="sqlDataSource" AutoPostBack="True" DataTextField="nome" DataValueField="idImpianto" OnDataBound="DropDownList1_DataBound">
</asp:DropDownList><asp:SqlDataSource OnSelecting="SqlDataSource1_Selecting" ID="sqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString_Access %>"
SelectCommand="SELECT * FROM [tabella]" DataSourceMode="DataReader" ProviderName="<%$ ConnectionStrings:ConnectionString_Access.ProviderName %>"></asp:SqlDataSource>
</p>
///cs
protected void Page_Load(object sender, EventArgs e)
{
}
if (this.Addtutti == true)
{
ListItem li = this.DropDownList1.Items.FindByValue(defaultValueX);
if (li == null)
{
this.DropDownList1.AppendDataBoundItems = true;
this.DropDownList1.Items.Insert(0, new ListItem("Tutto", defaultValueX));
this.DropDownList1.SelectedIndex = 1;
}
}
if (this.SelectParameters != null )
{
if (!IsPostBack && this.sqlDataSource.SelectParameters.Count ==0)
{
for (int i = 0; i < this.SelectParameters.Count; i++)
{
if (this.SelectParameters[i].GetType().ToString() == "System.Web.UI.WebControls.ControlParameter")
{
ControlParameter ctrp = new ControlParameter();
ctrp = (ControlParameter)this.SelectParameters[i];
ctrp.DefaultValue = "1";
this.sqlDataSource.SelectParameters.Add(ctrp);
}
else
if (this.SelectParameters[i].DefaultValue != "")
this.sqlDataSource.SelectParameters.Add(new Parameter(this.SelectParameters[i].Name, this.SelectParameters[i].Type, this.SelectParameters[i].DefaultValue));
else
this.sqlDataSource.SelectParameters.Add(new Parameter(this.SelectParameters[i].Name, this.SelectParameters[i].Type, "-1"));
}
}
}
private ParameterCollection m_parametriSqlDataSource;
[PersistenceMode(PersistenceMode.InnerProperty)]
public ParameterCollection SelectParameters
{
get
{
return this.m_parametriSqlDataSource;
}
set
{
this.m_parametriSqlDataSource = value;
}
}
//questa linea era solo un test
ctrp.DefaultValue = "1"