Databound DataField not getting populated
I'm currently analyzing the code behind for a web application. The Default page contains a GridView with several bound DataFields that are supposed to be populated, when the page loads and reloads, with data based on a URL parameter that's passed on initial load. The way it works in summary is this:
-I have a GridView1_Init
method that is called when the page loads, this retrieves data using an OldDbConnection and a URL parameter appended as part of the OleDbCommand SQL statement.
-The data is read and stored in the Web.config file. At this point, when debugging, I can see and verify the there is data being retrieved.
-Now I'm calling a Grid开发者_如何学编程View1_RowDataBound
method to populate each row. I have it in the Default.aspx page within the GirdView parameters as OnRowDataBound="GridView1_RowDataBound"
My problem is that this method never gets called for one of the URL parameters I'm passing and as a result the Databound rows in the GridView don't get populated and the page displays nothing. I have another URL parameter I use to test and it works perfectly with that one, i.e. the page loads with the Gridview displaying all the data as expected. I'm not sure why the method GridView1_RowDataBound
is getting called for one URL parameter, but not for the other. I've debugged using both and also ran the query in SQL Server Management Studio and I am getting data back for both. Thanks in advance for your help.
I'm not sure.. but try these 1-on the page load define a GridView1.datasource=....; GridView1.Databind(); 2-check the html tags are formed correctly.
Ok, I did a little more digging using Visual Studio and SQL Server Management Studio and first determined that the gridview was using a different stored procedure, than the one I was referencing, to populate the grid. Second, after rummaging through the database, I discovered that the table being referenced for data to populate the grid was empty. After inserting some test data, I went back and reran the application and finally had some data being displayed in the grid. Always the little things.
精彩评论