Foros del Web » Programación para mayores de 30 ;) » .NET »

No funciona el DataBind() para un checkboxlist

Estas en el tema de No funciona el DataBind() para un checkboxlist en el foro de .NET en Foros del Web. Hola! No se cual sea mi error, hago una consulta a la BD por un stored procedure y hago un bind a mi datalist: Código: ...
  #1 (permalink)  
Antiguo 19/09/2006, 14:39
 
Fecha de Ingreso: mayo-2006
Mensajes: 243
Antigüedad: 18 años
Puntos: 0
Pregunta No funciona el DataBind() para un checkboxlist

Hola!

No se cual sea mi error, hago una consulta a la BD por un stored procedure y hago un bind a mi datalist:

Código:
sqlConexion = new SqlConnection((String) strConn);
sqlComando = new SqlCommand();
// Abrirmos la conexion
sqlConexion.Open();
	
// Comenzamos a preparar los comandos
sqlComando.Connection = sqlConexion;
sqlComando.CommandText = "LstBusqNoticias " + Ciudad + ", " + TituloText + ", " + TextoText +  ", " + IdNoticia;
sqlComando.CommandType = CommandType.Text;
rs=sqlComando.ExecuteReader();

if (rs != null && rs.HasRows)
{
             MyDataList.Visible=true;
	noDatos.CssClass="tit";
	noDatos.Text="Noticias";
	noDatos.Visible=true;
	linea_gruesa4.Visible=true;
	MyDataList.DataSource = rs;
	MyDataList.DataBind();
}
Dentro del databind tengo un checkboxlist y dos label, en los label si se muestran los datos,pero en el checkboxlist no:

Código:
<TD align="center"><asp:datalist id="MyDataList" runat="server" Height="56" Width="320" OnCancelCommand="Cancelar"
...
...
...
<ItemTemplate>
...
...
...

<TD width="50px" align="center">
<asp:label id="LabelId" runat="server" CssClass="tx2" Height="16px" Text='<%# DataBinder.Eval(Container.DataItem, "id_noticia") %>' ></asp:label>
</TD>
<TD align="left" width="668px">

<asp:label id="LabelTitulo" runat="server" CssClass="tx2" Height="16px" Text='<%# DataBinder.Eval(Container.DataItem, "titulo") %>'>

</asp:label>
<TD align="left" width="32px">

<asp:CheckBoxList runat="server" ID="ChkNoticia" DataValueField= '<%# DataBinder.Eval(Container.DataItem, "id_noticia") %>'>

<asp:ListItem></asp:ListItem>
</asp:CheckBoxList>

</TD>

...
...
...
</ItemTemplate>
Por que no me esta tomando el value para el checkbox???
  #2 (permalink)  
Antiguo 19/09/2006, 17:08
 
Fecha de Ingreso: mayo-2006
Mensajes: 243
Antigüedad: 18 años
Puntos: 0
he decidido hacer un llenado aparte para el checkboxlist.

de la siguiente manera:

Código:
SqlConnection sqlConexion = null;   
SqlCommand sqlComando = null; 
SqlDataReader rs = null;
try
{
	// Creamos la conexión
	string strConn = System.Configuration.ConfigurationSettings.AppSettings["MyConexion"];
	sqlConexion = new SqlConnection((String) strConn);
	sqlComando = new SqlCommand();
	// Abrirmos la conexion
	sqlConexion.Open();
		
	// Comenzamos a preparar los comandos
	sqlComando.Connection = sqlConexion;
	sqlComando.CommandText = "LstBusqNoticias " + Ciudad + ", " + TituloText + ", " + TituloText +  ", " + IdNoticia;
	sqlComando.CommandType = CommandType.Text;
	rs=sqlComando.ExecuteReader();

	if(rs.HasRows)
	{
		ChkNoticia.DataSource = rs;
		ChkNoticia.DataTextField = "titulo";
		ChkNoticia.DataValueField="id_noticia";
		ChkNoticia.DataBind();
	}
pero me marca el siguiente error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 1362: if(rs.HasRows)
Line 1363: {
Line 1364: ChkNoticia.DataSource = rs;
Line 1365: ChkNoticia.DataTextField = "titulo";
Line 1366: ChkNoticia.DataValueField="id_noticia";


Source File: c:\documents and settings\my documents\visual studio projects\fisherproject\alta_modifica_programacion. aspx.cs Line: 1364

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
FisherProject.alta_modifica_programacion.LlenaChec kBox() in c:\documents and settings\my documents\visual studio projects\fisherproject\alta_modifica_programacion. aspx.cs:1364
FisherProject.alta_modifica_programacion.BuscarNot iciaButton_Click(Object sender, ImageClickEventArgs e) in c:\documents and settings\my documents\visual studio projects\fisherproject\alta_modifica_programacion. aspx.cs:553
System.Web.UI.WebControls.ImageButton.OnClick(Imag eClickEventArgs e)
System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain() +1292
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:10.