Solved

GridView not visible

Posted on 2008-10-12
2
1,011 Views
Last Modified: 2012-05-05
I have a GridView control on my Web Form. I am filling the rows on Page_Load. The query is correct and showing all rows when run from SQL Server Management Studio. But when this query is executed from ASP.NET, the GridView is not visible.
protected void Page_Load(object sender, EventArgs e)
    {
        FillGrid();
    }
 
    protected void FillGrid()
    {
         SqlDataReader dr = ReUse.ReturnDR("SELECT CATEGORYNAME FROM CATEGORYMASTER ORDER BY CATEGORYNAME");
        gvCategory.DataSource = dr;
    }
 
public static class ReUse
{
    #region Return DataReader
    public static SqlDataReader ReturnDR(string sqlQuery)
    {
        OpenConnection();
        SqlCommand cmd = new SqlCommand(sqlQuery, CN);
        SqlDataReader dr = null;
 
        try
        {
            dr = cmd.ExecuteReader();
            dr.Read();
            return dr;
        }
        finally
        {
            CloseConnection();
            cmd.Dispose();
        }

Open in new window

0
Comment
Question by:rpkhare
2 Comments
 
LVL 11

Accepted Solution

by:
Anurag Agarwal earned 50 total points
ID: 22700420
I guess after

gvCategory.DataSource = dr;

you have to call

gvCategory.DataBind();


Anurag
0
 
LVL 8

Author Closing Comment

by:rpkhare
ID: 31505550
Oh. what a shit mistake it was.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question