<p>I'm coming from a Rails background and doing some work on a ASP.NET project (not ASP MVC). Newbie question: what's the easiest way to make a custom editor for a table of records?</p>

<p>For example: I have a bunch of data rows and want to change the "category" field on each -- maybe a dropdown, maybe a link, maybe the user types it in.</p>

<p>In Rails, I'd iterate over the rows to build a table, and would have a form for each row. The form would have an input box or dropdown, and submit the data to a controller like "/item/edit/15?category=foo" where 15 was the itemID and the new category was "foo".</p>

<p>I'm new to the ASP.NET model and am not sure of the "right" way to do this -- just the simplest way to get back the new data &amp; save it off. Would I make a custom control and append it to each row? Any help appreciated.</p>

[{'answer_id': 12715, 'author': 'Adam Lassek', 'author_id': 1249, 'author_profile': 'https://Stackoverflow.com/users/1249', 'pm_score': 0, 'selected': False, 'text': '<p>There are a few controls that will do this for you, with varying levels of complexity depending on their relative flexibility. </p>\n\n<p>The traditional way to do this would be the DataGrid control, which gives you a table layout. If you want something with more flexibility in appearance, the DataList and ListView controls also have built-in support for editing, inserting or deleting fields as well.</p>\n\n<p>Check out <a href="http://mattberseth.com/" rel="nofollow noreferrer">Matt Berseth\'s blog</a> for some excellent examples of asp.net controls in action.</p>\n'}, {'answer_id': 12719, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 3, 'selected': True, 'text': '<p>You can REALLY cheat nowadays and take a peek at the new Dynamic Data that comes with .NET 3.5 SP1. Scott Guthrie has a blog entry demoing on how quick and easy it\'ll flow for you here:</p>\n\n<p><a href="http://weblogs.asp.net/scottgu/archive/2007/12/14/new-asp-net-dynamic-data-support.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2007/12/14/new-asp-net-dynamic-data-support.aspx</a></p>\n\n<p>Without getting THAT cutting edge, I\'d use the XSD generator to generate a strongly typed DataSet that coincides with the table in question. This will also generate the TableAdapter you can use to do all your CRUD statements. </p>\n\n<p>From there, bind it to a DataGrid and leverage all the standard templates/events involved with that, such as EditIndex, SelectedIndex, RowEditing, RowUpdated, etc.</p>\n\n<p>I\'ve been doing this since the early 1.0 days of .NET and this kind of functionality has only gotten more and more streamlined with every update of the Framework.</p>\n\n<p>EDIT: I want to give a quick nod to the Matt Berseth blog as well. I\'ve been following a lot of his stuff for a while now and it is great!</p>\n'}, {'answer_id': 12873, 'author': 'Kalid', 'author_id': 109, 'author_profile': 'https://Stackoverflow.com/users/109', 'pm_score': 0, 'selected': False, 'text': '<p>Thanks for the answers guys. It looks like customizing the DataGrid is the way to go. For any ASP.NET newbies, here\'s what I\'m doing</p>\n\n<pre><code>&lt;asp:DataGrid ID="GridView1" runat="server" AutoGenerateColumns="False"&gt;\n    &lt;Columns&gt;\n        &lt;asp:BoundColumn DataField="RuleID" Visible="False" HeaderText="RuleID"&gt;&lt;/asp:BoundColumn&gt;\n        &lt;asp:TemplateColumn HeaderText="Category"&gt;\n        &lt;ItemTemplate&gt;\n            &lt;!-- in case we want to display an image --&gt;\n            &lt;asp:Literal ID="litImage" runat="server"&gt;\n            &lt;/asp:Literal&gt;\n            &lt;asp:DropDownList ID="categoryListDropdown" runat="server"&gt;&lt;/asp:DropDownList&gt;\n         &lt;/ItemTemplate&gt;\n        &lt;/asp:TemplateColumn&gt;\n\n    &lt;/Columns&gt;\n&lt;/asp:DataGrid&gt;\n</code></pre>\n\n<p>This creates a datagrid. We can then bind it to a data source (DataTable in my case) and use things like </p>\n\n<pre><code>foreach (DataGridItem item in this.GridView1.Items)\n{\n     DropDownList categoryListDropdown = ((DropDownList)item.FindControl("categoryListDropdown"));\n     categoryListDropdown.Items.AddRange(listItems.ToArray());\n}\n</code></pre>\n\n<p>to populate the intial dropdown in the data grid. You can also access item.Cells[0].text to get the RuleID in this case.</p>\n\n<p>Notes for myself: The ASP.NET model does everything in the codebehind file. At a high level you can always iterate through GridView1.Items to get each row, and item.findControl("ControlID") to query the value stored at each item, such as after pressing an "Update" button.</p>\n'}]
['https://Stackoverflow.com/questions/12706', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/109/']