Hola...acá otra vez.
Logré ejecutarlo y no me arroja ningún error. Me muestra la página pero...plop, no me muestra el Gridview, lo único que me muestra es el label.
Les dejo el código para que me puedan guíar y así corregir lo que este malo.
nota:
La tabla contiene datos.
Le puse puntos de interrupción y verifiqué que el cnx no venga null.
Revisé la consulta con el sql server y me muestra los datos.
Conexión en el web config.
----------------------------------
<connectionStrings>
<add name="Grid" connectionString="Data
Source=FXS\SQLEXPRESS;Initial
Catalog=USUARIOS;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
------------------------------------------------------------------
Default.aspx
----------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ASPNETFuturesEnabledWebApplication1._Def ault" %>
<!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>Llenado de GridView</title>
<link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Label ID="LBL1" Text="Grilla Prueba" runat="server"></asp:Label>
<asp:GridView ID="GV1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Nombre" DataField="NOMBRE"
SortExpression="NOMBRE"><ItemStyle HorizontalAlign="Left"
VerticalAlign="Top" /></asp:BoundField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
--------------------------------------------------------------------------------------------------------
Default.aspx.cs
--------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
namespace ASPNETFuturesEnabledWebApplication1
{
public partial class _Default : System.Web.UI.Page
{
DataSet dataSetOrg = new DataSet();
SqlConnection cnx = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["Grid"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
cnx.Open();
string Consulta = "SELECT NOMBRE FROM CONTACTOS";
SqlCommand Orden = new SqlCommand(Consulta, cnx);
SqlDataReader Lector = Orden.ExecuteReader();
GV1.DataSource = Lector;
}
}
}
Salu2 y gracias.