{"id":188,"date":"2010-05-18T18:57:50","date_gmt":"2010-05-18T13:27:50","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=188"},"modified":"2010-05-18T18:57:50","modified_gmt":"2010-05-18T13:27:50","slug":"asp-net-datagrid-basic-questions","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/asp-net-datagrid-basic-questions\/","title":{"rendered":"ASP.NET DataGrid basic questions"},"content":{"rendered":"<ol>\n<li><strong>What is datagrid?<\/strong> 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.<\/li>\n<li><strong>What&#8217;s the difference between the\u00a0<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfSystemWebUIWebControlsDataGridClassTopic.asp\">System.Web.UI.WebControls.DataGrid<\/a> and\u00a0<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfSystemWindowsFormsDataGridClassTopic.asp\">System.Windows.Forms.DataGrid<\/a>?<\/strong> 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.<\/li>\n<li><strong>How do you customize the column content inside the datagrid?<\/strong> 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.<\/li>\n<li><strong>How do you apply specific formatting to the data inside the cells?<\/strong> You cannot specify formatting for columns generated when the grid&#8217;s AutoGenerateColumns property is set to true, only for bound or template columns. To format, set the column&#8217;s DataFormatString property to a string-formatting expression suitable for the data type of the data you are formatting.<\/li>\n<li><strong>How do you display an editable drop-down list?<\/strong> 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 &#8220;\u201d for example, if a book&#8217;s genre is set to &#8220;fiction,&#8221;\u009d when the drop-down list displays, you often want &#8220;fiction&#8221;\u009d to be preselected.<\/li>\n<li><strong>How do you check whether the row data has been changed?<\/strong> 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&#8217;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.<\/li>\n<\/ol>\n<p>You can find more questions on Datagrid at <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/Aa289519\">http:\/\/msdn.microsoft.com\/en-us\/library\/Aa289519<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is datagrid? 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[21],"tags":[43,71],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-net","tag-asp-net","tag-datagrid"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1178,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/datagrid-gridview-datalist-and-repeater-control-in-asp-net\/","url_meta":{"origin":188,"position":0},"title":"DataGrid, GridView, DataList and Repeater Control in ASP.net","author":"Jitendra","date":"October 1, 2010","format":false,"excerpt":"DataGrid, GridView, DataList and Repeater Control in ASP.net","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":191,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/datagrid-example-part-1\/","url_meta":{"origin":188,"position":1},"title":"DataGrid Example &#8211; Part 1","author":"Jitendra","date":"May 18, 2010","format":false,"excerpt":"For the basics of DataGrid please refer this post: https:\/\/jitendrazaa.com\/blog\/?p=188 In this example, i will explain the basics of DataGrid control like Theming, Databinding etc. We will start our example with creating the SQL Express database of Employee which will contain the following fields : Id, FName, LName, Email. Now\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/Employee.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":227,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/datagrid-example-sorting-part-2\/","url_meta":{"origin":188,"position":2},"title":"DataGrid Sorting and Paging Example \u2013 Part 2","author":"Jitendra","date":"May 18, 2010","format":false,"excerpt":"For Part 1, visit This URL\u00a0https:\/\/jitendrazaa.com\/blog\/?p=191 In this part, i will show that how to Sort the Datagrid Component of ASP.NET. To sort Datagrid, we will need DataView and then assign Dataview as datasource to our Grid control. We will need to change our code of Part 1. Previously, we\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/Sorting1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5389,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/responsive-datagrid-component-in-lightning-basics\/","url_meta":{"origin":188,"position":3},"title":"Responsive Datagrid component in Lightning &#8211; Basics","author":"Jitendra","date":"March 15, 2016","format":false,"excerpt":"This blog post explains simple use case of Nested Lightning Component. It goes through example on how to interact and combine nested components to be used in parent Lightning component.","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Using Nested Lightning component to create responsive DataGrid","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Lightning-Data-Grid-1.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Lightning-Data-Grid-1.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/03\/Lightning-Data-Grid-1.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":790,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/row-expand-collapse-using-jquery-and-ajax\/","url_meta":{"origin":188,"position":4},"title":"Row expand collapse using jquery and Ajax","author":"Jitendra","date":"August 19, 2010","format":false,"excerpt":"Using JQuery and Ajax to expand and collapse the row in ASP.NET","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Ajax JQuery Row Expand Collapse","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/08\/rowexpand-300x203.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5970,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/generic-and-responsive-table-component-in-salesforce-lightning\/","url_meta":{"origin":188,"position":5},"title":"Generic and Responsive Table Component in Salesforce Lightning","author":"Jitendra","date":"March 31, 2017","format":false,"excerpt":"Complete Source code to create generic and responsive Table component in Salesforce Lightning","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"JSON format for responsive datagrid Lightning component","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2017\/03\/JSON-format-for-responsive-datagrid-Lightning-component.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}