hii all i am trying gridview control in my application.code is executing without errors.but i am not getting output means(internet explorer is coming blank).
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class GridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PopulateGrid();
}
public void PopulateGrid()
{
DataSet objDs = new DataSet();
String ConnectionString = "server=iconn;database=db_test;user id=sa;password=iconn;";
SqlConnection Conn = new SqlConnection(ConnectionString);
System.Data.SqlClient.SqlDataAdapter myCmd;
myCmd = new System.Data.SqlClient.SqlDataAdapter("StoredProcedure1", Conn);
myCmd.SelectCommand.CommandType = CommandType.StoredProcedure;
Conn.Open();
myCmd.Fill(objDs);
GridView1.DataSource = objDs;
GridView1.DataBind();
//Conn.Close();
}
public void ItemDataBoundEventHandler1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover","this.style.backgroundColor='Silver'");
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor='#FFFBD6'");
}
}
}
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="ItemDataBoundEventHandler1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
Create PROCEDURE StoredProcedure1
AS
select * from tbl_dtGrid
RETURN
i have taken the table as tbl_dtGrid with two columns as id and name