URGENT & EASY ASP using C# populating datagrid

I am having a hard time getting my datagrid to show my data. What do I need to do to make this work?

I am using .NET 2008

I removed parts of my connection string but it does connect

I would really like to put the data in an object instead so if you have an example of that that would be great as well
default.aspx file:
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="2px" 
            CellPadding="4" GridLines="Vertical">
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                <Columns>
                    <asp:BoundField AccessibleHeaderText="Feed_Number" HeaderText="Feed Number" />
                    <asp:BoundField AccessibleHeaderText="Dept_Feed_Name" 
                        HeaderText="Department Feed Name" />
                    <asp:ButtonField AccessibleHeaderText="Select" Text="Select">
                    <ControlStyle Font-Underline="True" ForeColor="Blue" />
                    </asp:ButtonField>
                </Columns>
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#DCDCDC" />
    </asp:GridView>
 
default.aspx.cs file
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Odbc;
using System.Data.OracleClient;
using System.Data;
using Dean_Data_Composer;
using System.Configuration;
 
namespace Dean_Data_Composer
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check active directory to see if user allowed to view this
            DeptFeedOracleConnection();
        }
 
        public void DeptFeedOracleConnection()
        {
            //string connectionString = "Data Source=SERVER1;Persist Security Info=True; User=user1; Password=@passw";
            using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString))
            {
                connection.Open();
 
                try
                {
                    DataSet ds = new DataSet();
                    OracleCommand cmd = connection.CreateCommand();
                    cmd.CommandText = "Select * from DEPT_FEED";
 
                    OracleDataAdapter oda = new OracleDataAdapter();
 
                    oda.SelectCommand = cmd;
                    oda.Fill(ds, "DEPT_FEED");
 
                    /// clear the grids data source
                    GridView1.DataSource = null;
 
                    DataTable dt = new DataTable();
 
                    dt = ds.Tables["DEPT_FEED"];
 
                    DataView dv = new DataView(dt);
 
                    dv = ds.Tables["DEPT_FEED"].DefaultView;
 
                    // Bind the data table to the data grid
                    GridView1.DataSource = dv;
                    GridView1.DataBind();
 
 
                    foreach (DataTable t in ds.Tables)
                    {
                        Response.Write("Table: " + t.TableName + " is in Dataset");
                        Response.Write("Row 0, Column 2: " + t.Rows[0][2]);
                        Response.Write("Row 1, Column 2: " + t.Rows[1][2]);
                        Response.Write("Row 2, Column 2: " + t.Rows[2][2]);
                        Response.Write("Row 3, Column 2: " + t.Rows[3][2]);
 
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("There was some error connecting to the database" + "DB Error: " + ex.ToString());
                }
                finally
                {
                    //Don't keep the connection open. 
                    connection.Close();
                }
            }
 
        }
    }
}

Open in new window

LVL 2
NewMom2BrandonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guru_samiCommented:
You have BoundFields but you did not specify and DataFied ..it should be the name of the column from your table.
e.g. Feed_Number is a column from your table..
 <asp:BoundField AccessibleHeaderText="Feed_Number" HeaderText="Feed Number" DataFied= "Feed_Number" />
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AsishRajCommented:
Yeap Guru Sami has identified for you

 DataFied= "Feed_Name" is missing in your gridview

That is the reason no data is shown in the gridview
0
sandip-mishraCommented:
Hi , i have used your code and its working fine for me.. The fiffrence is in the aspx page.


aspx...

<asp:GridView runat="server" ID="GridView1"  AutoGenerateColumns="False" >
            <Columns>
                <asp:BoundField DataField="a" HeaderText="a" SortExpression="a" />
                <asp:BoundField DataField="b" HeaderText="b" SortExpression="b" />
                <asp:BoundField DataField="c" HeaderText="c" SortExpression="c" />
                <asp:BoundField DataField="no" HeaderText="no" SortExpression="no" />
                <asp:BoundField DataField="x" HeaderText="x" SortExpression="x" />
                <asp:CheckBoxField DataField="bol" HeaderText="bol" SortExpression="bol" />
            </Columns>
        </asp:GridView>

aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["Dynamics-ExchangeConnectionString"].ToString());
        try
        {
            GridView1.DataSource = null;
           
            SqlCommand sqlComd = new SqlCommand();
            sqlComd.Connection = sqlConn;
            sqlComd.CommandType = CommandType.Text;
            sqlComd.CommandText = "select * from a";
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            da.SelectCommand = sqlComd;
            da.Fill(ds, "DEPT_FEED");
            DataTable dt = new DataTable();
            dt = ds.Tables["DEPT_FEED"];
            DataView dv = new DataView(dt);
            dv = ds.Tables["DEPT_FEED"].DefaultView;
            GridView1.DataSource = dv;
            GridView1.DataBind();
            foreach (DataTable t in ds.Tables)
            {
                Response.Write("Table: " + t.TableName + " is in Dataset");
                Response.Write("Row 0, Column 2: " + t.Rows[0][2]);
                Response.Write("Row 1, Column 2: " + t.Rows[1][2]);
                Response.Write("Row 2, Column 2: " + t.Rows[2][2]);
                Response.Write("Row 3, Column 2: " + t.Rows[3][2]);

            }
        }
        catch
        {

        }
        finally
        {
            sqlConn.Close();

        }

    }


I have used a Sql Database and you have used Oracle Database, but it doesnt matter. I have taken a diffrent table(dummy table).

You can try the code that i have pasted in aspx...... its only the Datafield.

Regards

Sandip Mishra
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.