I am new ASP.NET and I have never used a GridView or DataGrid, but I cannot find helpful examples online on how to do what I need. I need some data to be displayed on a page and I know that I should use a GridView, but I cannot seem to get anything to display.
I have the following DataSet:
DataSet ds = new DataSet("MyTables");
ds.Tables.Add("Users");
ds.Tables["Users"].Columns.Add("ID");
ds.Tables["Users"].Columns.Add("Name");
ds.Tables["Users"].Columns.Add("Email");
ds.Tables["Users"].Rows.Add(0,"Ace","ace@example.com");
ds.Tables["Users"].Rows.Add(1,"Biff","biff@example.com");
ds.Tables["Users"].Rows.Add(2,"Chuck","chuck@example.com");
ds.Tables["Users"].Rows.Add(3,"Dick","dick@example.com");
myGrid.DataSource = ds.Tables["Users"].DefaultView;
myGrid.DataBind();
Heres is my ASP.NET:
<asp:GridView ID="myGrid" runat="server">
</asp:GridView>
I’m thinking that you’re getting a object null reference error. What’s happening is that you’re creating columns in a table called ‘add users’ where there is no table called ‘add users’. If you just change the three lines that you have ds.Tables[“Add Users”] and change that to just ds.Tables[“Users”] everything should work out just fine.
Hope this works for you.