Library tutorials & articles

Web Forms DataGrid and DataSet Programming

FAQ's

Q. Why doesn't my default GridLayout project display correctly in Netscape 4.7.
A . For maximum compatibility, try building your project using FlowLayout and nested tables.

Q. Why doesn't my DataGrid show up when I run the project? I can see it in the design view.
A. You need to fill the DataSet and call DataBind in Page_Load.

sqlDataAdapter1.Fill(dataSet11);
...
DataGrid1.DataBind();

Q. Why are all of my changes lost on post back?
A. Don't call DataBind except on the initial page load or in your event handlers, allowing the grid to be repopulated from the ViewState.

// This code executes every time
sqlDataAdapter1.Fill(dataSet11);
// This code executes the first time only
if (!IsPostBack)
{
    DataGrid1.DataBind();
}

Q. Why can't I debug?
A. Under IIS Properties --> Directory Security --> Anonymous Access Edit --> Enable Integrated Windows Authentication.

Q. Why do I need a logon password to access a web page directly from IE?
A. Enable Guest Account ant then under Control Panel --> User Accounts --> Change an Account --> Guest --> Remove the password.

Q. How do I turn off auto formatting in the HTML view?
A. Go to Tools --> Options... --> Text Editor --> HTML/XML --> HTML Specific and disable "Statement Completion".

Q. Why are the instance variables re-initialized on post back?
A. Since the web is by nature stateless, changes to a instance variable are lost on post back. To implement "state", you must manually write the value of the variable to the ViewState object and then read the saved value of the variable from the ViewState on post back.

// This code executes the first time only
if (!IsPostBack)
{
    view.Sort = "au_id"+ " ASC";
    ViewState["LastSortOrder"]="ASC";
    ViewState["LastSortColumn"]= "au_id";
    ViewState["LastFilter"]= "";
    DataGrid1.DataBind();
}
else // This code executes only on post back
{
    string lastSortColumn= (string)ViewState["LastSortColumn"];
    string lastSortOrder= (string)ViewState["LastSortOrder"];
    string lastFilter= (string)ViewState["LastFilter"];
    view.Sort= lastSortColumn+ " "+ lastSortOrder;
    view.RowFilter= lastFilter;
}

Comments

  1. 26 Jan 2006 at 14:50
    How could i do all this with untyped dataset from xml source? (no find methods etc..)
    Vjero
  2. 23 Nov 2005 at 14:26

    hi
    hey ppl i m   inserting some data manually in a dataview then i m sorting that dta via dataview.sort , sorting is taking place perfectly here but when i embed this data into a word document  then  i found that data is not  in sorted order as this supposed to be but it is in order in which it had typed...........so guys if u  have have any solution of this problem  then plz  mail me at aman_105@rediffmail.com

  3. 10 Nov 2005 at 09:33

    hello
     I am converting C#.net code into vb.net code .
     Sorting ASC or DESC  is not working .
     while degugging ,code work fine but i think some how dataset is not getting refreshed.
     I have commented these line  'view.RowFilter = lastFilter' .Is it require for sorting
     Execpt that everything is same
      please help me out .
                                                Thanks            
     

  4. 30 Jun 2005 at 02:13

    Hi.


    I dont know if this only a problem of mine, but when I hit a sort column the DataGridSortCommand happens twice.


    Should this happen? In my case it happens and so all the code in that event doesnt work properly...


    Could some help me out on this one?


    TIA,
    C.C.

  5. 10 Nov 2004 at 09:24
    How do I obtain ResetPageIndex? It is unknown to my installation of .NET or at least to the libraries I am using.
  6. 01 May 2004 at 12:13

    Jeff,


    Thanks a bunch!  I am new to ASP.NET programming and it was having a devil of a time getting my datagrid to sort -- your example provided the one missing link: the DataSource property should have been set to the view and not the dataset! Tanx again.


    --Babak

  7. 01 Jan 1999 at 00:00

    This thread is for discussions of Web Forms DataGrid and DataSet Programming.

Leave a comment

Sign in or Join us (it's free).

Jeff Louie
AddThis

Related podcasts

Events coming up

  • Nov 18

    15 Minutes of Fame

    Dresher, United States

    This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.

Want to stay in touch with what's going on? Follow us on twitter!