All Time DataGrid – Gridview Interview Questions
1. What is a DataGrid or Grid View?
The DataGrid Web server control is a powerful tool for displaying information from a data source. It is easy to use; you can display editable data in a professional-looking grid by setting only a few properties.
At the same time, the grid has a sophisticated object model that provides you with great flexibility in how you display the data.
2. What is the difference between the System.Web.UI.WebControls.DataGrid and and System.Windows.Forms.DataGrid?
The Web UI control does not inherently support master-detail data structures. As with other Web server controls, it does not support two-way data binding. If you want to update data, you must write code to do this yourself. You can only edit one row at a time. It does not inherently support sorting, although it raises events you can handle in order to sort the grid contents. You can bind the Web Forms
DataGrid to any object that supports the IEnumerable interface. The Web Forms DataGrid control supports paging. It is easy to customize the appearance and layout of the Web Forms DataGrid control as compared to the Windows Forms one.
3. How do you check whether the row data has been changed?
The definitive way to determine whether a row has been dirtied is to handle the changed event for the controls in a row. For example, if your grid row contains a TextBox control, you can respond to the control’s TextChanged event.
Similarly, for check boxes, you can respond to a CheckedChanged event. In the handler for these events, you maintain a list of the rows to be updated. Generally, the best strategy is to track the primary keys of the affected rows. For example, you can maintain an ArrayList object that contains the primary keys of the rows to update.
4. Why can not I edit the results of a query in the SQL Editor?
Query statements MUST return the ROWID to be updatable. For example:
select * from employee where salary > 2000
would not be updatable, whereas:
select employee.*, rowid from employee where salary > 2000
would be updatable.
To reduce this obvious nuisance, you can use the TOAD-specific EDIT statement. For example:
edit employee where salary > 2000
If the resultset should be editable but remains read-only, make sure the TOAD Options > Data Grids – Data tab, Default to Read-Only Queries checkbox is NOT enabled
5. Why can not I add a new record by hitting the down arrow key in the data tab?
Please upgrade your copy of TOAD to at least version 7.4.0.3. This functionality has been restored.
6. What is the OCI Buffer Array Size option for in the View – Options – Oracle – General section?
After a SELECT query is executed, we must retrieve the rows from the Oracle server to your PC. We do not retrieve the rows all at once, nor do we retrieve them one at a time (unless there is a LONG or LOB column involved). We retrieve the rows in blocks. The number of rows retrieved in each block is the number of rows you specify with “OCI Array Buffer Size”. TOAD defaults to 25 because SQL*Plus defaults to 25. In my opinion, an optimal setting is more like 500 or 1000.
Here is why: If your dataset has 1,000 rows, and your OCI Array Buffer size is set to 25, then TOAD has to make 40 (that’s 1000 / 25) round trips across the network to retrieve all of the rows. So you can immediately see why 500 or 1000 is better. The only disadvantage to a higher setting of OCI Array Buffer Size is that TOAD must allocate memory to hold that many rows prior to each fetch.
If that many rows are actually fetched, there is no loss. On the other hand, if not that many rows are retrieved, then we allocated some memory that is not going to be released until the cursor is freed. Luckily, this is a trivial amout of memory, in the grand scheme of things.
7. What is the Clone Cursor Options for on the SaveAs dialogs in the Schema Browser and (SQL) Editor?
When “Clone Cursor” is turned OFF, and a user goes to the “save as” screen and begins an export, we use the actual cursor which is tied to the data grid. The advantage to this is that the query does not need to be re-executed. The disadvantage to this is that the whole dataset must be held in your PC’s RAM, because this is a scrollable dataset (it is this mechanism that allows scrolling in the grids).
When “Clone Cursor” is turned ON, and a user goes to the “save as” screen and begins an export, we create a new, non-scrollable cursor. The advantage here is that as rows are read in and sent to the destination file, we don’t have to hold them in memory any longer…and a minimal amout of RAM is used. The disadvantage is that for this to happen, the query must be re-executed. So…which setting should you use? If your query returns a LOT of rows (too many to hold in your PC’s RAM), you should have “Clone Cursor” turned ON…even if your query takes a long time to execute.
If your query returns a number of rows such that the entire dataset will easily fit into your PC’s memory, then we should consider the execution time for the query. If execution time is slow, then leave “Clone Cursor” OFF. If execution time is fast, then it doesn’t really matter.
This option has been renamed to “Display all exported results in grid” for version 9.1. It will be greyed out if the dataset being exported has already been completely fetched, e.g. OCI Array = 500 and only 125 records, or you have already scolled to the bottom of the result set. If either of these cases are not true, then if this option IS set, Toad will execute the statement again and fetch ALL of the rows for the export, and then also send the entire result set to the original data grid so you can see them there too after the export has finished.
8. Explain My string data is all coming out as question marks?
We have found that this happens when the database character set is WE8ISO8859P1, and the Oracle client is 9.2.0.1. This is an Oracle bug, and upgrading your client to 9.2.0.4 or higher should resolve the problem. In any other case, please generate a TOAD Support Bundle from the Help menu and let us know what you are seeing.
9. How do I delete a record?
Assuming that the result set is editable (i.e. you have written a query that includes the ROWID, or you have used the TOAD Edit command), you can do one of the following:
*
“Delete row” button on the SQL Editor toolbar
*
CTRL+Del
*
Single Record View, Delete Button
10. How can I see the data in nested tables?
TOAD 7.5 and up can show nested table data in popups from the data grids if you are using an 8.0 or higher Oracle client. The nested table data will appear in the grid cell as “(DATASET)”. Right-click over this cell and choose “Popup editor”. TOAD 9.0.1 now supports nested table data in its “run as script” function. TOAD versions 7.4 and previous do not support nested table data due to a limitation in their data layer.
11. How can I see nested object data?
TOAD 7.5 and up can show nested object type data in popups from the data grids if you are using an 8.0 or higher Oracle client. Right-click on the cell that should contain the data and choose “Popup editor”. TOAD 9.0.1 now supports nested object data in its “run as script” function. TOAD versions 7.4 and previous do not support nested object data due to a limitation in their data layer.
12. How can I see TIMESTAMP and INTERVAL data?
TOAD 7.5 and up can show TIMESTAMP and INTERVAL data in its data grids if you are using a 9.0.1 or higher Oracle client. TOAD 9.0.1 supports TIMESTAMP and INTERVAL data in its “run as script” function. TOAD versions 7.4 and previous do not support TIMESTAMP and INTERVAL data due to a limitation in their data layer.
To see timestamp/intervals in the “datatype” drop down in the Create/Alter Table window, and in the “Add Column” window, go to options ? datatypes, and make sure “Include Timestamp/Interval Types” is checked.
13. Why can not I set a style in my XLS SaveAs exports of DataGrid data?
Try upgrading to the current release of TOAD, as we have obtained an updated XLS component. If you are still experiencing the problem, you can do this: FORMAT ? CELLS ? NUMBER TAB ? change to Currency, Percentage, etc.
14. Why does saving to XLS instance not work sometimes?
From the Toad lists.
One of my co-workers experiences a very strange problem. When he is saving the results of a query using “Save As” into Excel Instance nothing happens. There is 1 opened Excel and it stays empty. All other “save as” option work fine (including saving into Xls File).
What could be the problem?
John Dorlon replied :
*
Close excel.
*
Look in task manager.
*
If you still see excel running, kill it.
It seems that Excel gets confused as to whether it is running once or not and the hidden instance of Excel is causing the problem as it is most likely receiving the saved data. (explanation courtesy of Norm and it might even be right! LOL)
How do I name the tabs when I run a script?
15. How do I name the tabs when I run a script?
When you run a script in the MOE using F5, the output of the script is displayed at the bottom of the screen. Each command creates a separate tab for its results, as well as being included in the main script output tab. These tabs are simply named ‘Grid n’ where n is an incrementing number starting at 1. If you run a script with 5 SELECT statements, you get ‘Grid 1’ though ‘Grid 5’.
A question on the list from Roger Simoneau, asked how we could programatically rename the tabs from within the script. Both Erwin Rollauer and Ed Klinger (TeamT) supplied answers.
If you use the TTITLE directive before the SELECT statement, the tab will be named using the data from the TTITLE directive, as
Follows :
TTITLE today
SELECT sysdate FROM dual;
The tab for this statement will have the title ‘today’ exactly as entered.
If you need to use more than one word for the tab name, you must wrap the words in quotes, single ( ‘ ) or double ( ” ) work equally as well.
TTITLE “today is roughly around …”
SELECT sysdate FROM dual;
and see. I wonder if TTITLE actually stands for ‘Tab Title’? LOL.
16. How do I change the grid popup editor font?
Another one from the list. Herald asked > I changed the font for the DATA Grids, so I could look at Unicode. Now I see the chosen font in the datagrid, but if I open the popup editor it still gives the old font. Is it possible to change this font also, I didn’t find it in the options, or could you make the grid popup editor font the same as the data grid font.
After much searching, Brad supplied the following obvious LOL solution :
*
Go to View ? Toad Options ? Editor ? Behavior.
*
In the Languages section, select “Plain Text” from the dropdown and click the Edit … button next to the dropdown.
*
Go to the Highlighting tab and click the “custom font” button.
*
Choose your font and OK your way out.
17. How do you display an editable drop-down list?
Displaying a drop-down list requires a template column in the grid. Typically, the ItemTemplate contains a control such as a data-bound Label control to show the current value of a field in the record. You then add a drop-down list to the EditItemTemplate. In Visual Studio, you can add a template column in the Property builder for the grid, and then use standard template editing to remove the default TextBox control from the EditItemTemplate and drag a DropDownList control into it instead.
Alternatively, you can add the template column in HTML view. After you have created the template column with the drop-down list in it, there are two tasks. The first is to populate the list. The second is to preselect the appropriate item in the list — for example, if a book’s genre is set to “fiction,” when the drop-down list displays, you often want “fiction” to be preselected.
18. How do you hide the columns?
One way to have columns appear dynamically is to create them at design time, and then to hide or show them as needed. You can do this by setting a column’s Visible property.
19. How do you apply specific formatting to the data inside the cells?
You cannot specify formatting for columns generated when the grid’s AutoGenerateColumns property is set to true, only for bound or template columns. To format, set the column’s DataFormatString property to a string-formatting expression suitable for the data type of the data you are formatting.
20. How do you customize the column content inside the datagrid?
If you want to customize the content of a column, make the column a template column. Template columns work like item templates in the DataList or Repeater control, except that you are defining the layout of a column rather than a row.
21. What is asp.net?
ASP.NET is the latest version of Microsoft’s Active Server Pages technology (ASP).
ASP.NET is a part of the Microsoft .NET framework, and a powerful tool for creating dynamic and interactive web pages
22. How to sort the data in Datagrid ? when we use DataBound event of Datagrid, I want to display te data using controls….
For an example,
If i click a button, which is outside of the datagrid, entire data should be shown. 1st column in TextBoxs. second column in Drop down List Boxs..
How to bind the data in Dropdownlist,which is in DataGrid at run time?
Row1 Row2 Row3 Row4 —————– This is the record in datagrid…
When we click button (Bottom of the DataGrid), This Record should be shown…
Row1 in TextBox,,, Row2 in TextBox, Row3 in DropDownlistbox, Row4 in TextBox…
How to do this one?
Which event we should use?
Sorting in DataGrid.Using the SortCommand Event in the datagrid u can sort the value in datagrid.For Example.Dim con as new oledb.oledbconnection(“connectionstring”)con.open()Dim sql as stringsql=”query”Dim DataAdapter as new oledb.oledbdataadapter(sql,con)dim ds as new datasetdataadapter.fill(ds)Private Sub DGMain_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DGMain.SortCommand Dim datasort As
DataView datasort = LocalLibrary.GetDataSet(sql).Tables(0).DefaultView datasort.Sort = e.SortExpression DGMain.DataSource = datasort DGMain.DataBind() End SubBind the data in Datagrid at runtime ?Use ItemDataBound Event in datagrid.Private Sub DGMain_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DGMain.ItemDataBound If e.Item.ItemIndex > -1 Then Dim lblClose As dropdownlist lblClose = CType(e.Item.FindControl(“lblClose”), dropdownlist) If Not lblClose Is Nothing Then lblclose.items.add(“dropdownassignvalue”)lblclose.items(“dropdownindex”).value=”assigned value” End If End If End Sub
23. How to refresh the data in datagrid automatically?
For refreshing data in data grid control we can use chasing technique
24. How to add DateTime Control in ormal DataGrid Server Control?
cvv
using template column we can very well add date time control as child contorl
25. How can I view the Chinese and Japanese character sets through Toad?
Reset NLS_LANG on your Client machine to AMERICAN_AMERICA.JA16SJIS to view Japanese and AMERICAN_AMERICA.ZHT16BIG5 to view Chinese. Then change the font script for each language by right clicking on the data and choosing Grid Options | Data Grids – Visual | Fonts | Grid and choose Arial Unicode MS as the Font. This changes the script to Japanese for Japanese characters or to ChineseBig5 for Chinese.
26. How do I copy a whole row or multiple rows of data?
To copy one row of data, put your cursor in a cell in the grid and press Ctrl+Insert. This will copy the row and its column headers to the clipboard. To copy multiple rows of data, right-click in the grid and choose “Allow multiselect”. Use Shift-Click to select multiple adjacent rows, or use Ctrl+Click to select individual, non-adjacent rows. Press Ctrl+C. This will copy all of the rows and their column headers to the clipboard. To copy a single cell’s data, turn off “Allow multiselect”. Click on the cell you want to copy and press Ctrl+C.
The following table gives details of what happens with the various copy keys and multi-select options.
Multi-Select OFF Multi-Select ON
EDIT COPY CTRL+C CTRL+INS EDIT COPY CTRL+C CTRL+INS
One Cell Highlighted Cell only Cell only Row plus headings Cell only Cell Only Row plus headings
Many Cells(rows) highlighted N/A N/A N/A All highlighted rows plus headings All highlighted rows plus headings All highlighted rows plus headings
27. Why can not I add an entry via the grid for a table containing a CLOB column?
In older versions of TOAD, the grid is limited to adding/modifying CLOB’s for existing records. This should be working in TOAD 7.6. Note, however, that since TOAD does not support Unicode databases, that there are often errors when viewing CLOB data in the data grids for databases with Unicode character sets.
28. In DataGrid, is it possible to add rows one by one at runtime. That means after entering data in one row next row will be added?
Yes, for this you have to use datatable and after inserting the first row in datatable u have to bind that datatable to the grid and next time , first u have to add the row in datatable and next bind it to datagrid. keep on doing.
u have to maintain the datatable state.