Web Forms DataGrid and DataSet Programming


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.


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
// This code executes the first time only
if (!IsPostBack)

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["LastSortColumn"]= "au_id";
    ViewState["LastFilter"]= "";
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;

You might also like...



Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius