Note that there are some explanatory texts on larger screens.

plurals
  1. POInline Editing of a GridView
    text
    copied!<p>I have a grid view that I have populated in the code behind. I have enabled the AutoGenerateEditButton on this GridView but now cannot work out how to enable inline editing.</p> <p>I have looked for samples, and haven't found anything useful. Below is a copy of my ASPX page and then the code behind.</p> <p><strong>ProjectDetails.aspx</strong></p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProjectDetails.aspx.cs" Inherits="ProjectActions.ProjectDetails" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:GridView ID="ProjectDetailsGrid" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True" CellPadding="3" GridLines="Horizontal" BackColor="White" BorderColor="Black" BorderStyle="Solid" BorderWidth="6px"&gt; &lt;AlternatingRowStyle BackColor="#F7F7F7" /&gt; &lt;Columns&gt; &lt;asp:BoundField HeaderText ="ID" DataField="ActionID" /&gt; &lt;asp:BoundField HeaderText ="Summary" DataField="ActionSummary" /&gt; &lt;asp:BoundField HeaderText ="Description" DataField="ActionDescription" /&gt; &lt;asp:BoundField HeaderText ="Start Date" DataField="ActionStartDate" /&gt; &lt;asp:BoundField HeaderText ="Target Close Date" DataField="ActionTargetCloseDate" /&gt; &lt;asp:BoundField HeaderText ="Actual Close Date" DataField="ActionActualCloseDate" /&gt; &lt;asp:BoundField HeaderText ="Status" DataField="ActionStatus" /&gt; &lt;asp:BoundField HeaderText ="Owner" DataField="ActionOwner" /&gt; &lt;asp:BoundField HeaderText ="Last Modified" DataField="ActionLastModified" /&gt; &lt;asp:BoundField HeaderText ="Action Update" DataField="ActionUpdate" /&gt; &lt;/Columns&gt; &lt;FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /&gt; &lt;HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /&gt; &lt;PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /&gt; &lt;RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /&gt; &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /&gt; &lt;SortedAscendingCellStyle BackColor="#F4F4FD" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#5A4C9D" /&gt; &lt;SortedDescendingCellStyle BackColor="#D8D8F0" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#3E3277" /&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;/form&gt; &lt;asp:Label ID="ErrorMessage" runat="server" Text=""&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Label ID="SQLStatement" runat="server" Text=""&gt;&lt;/asp:Label&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>ProjectDetails.aspx.cs</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.Web.Configuration; using System.Text; using System.Data; namespace ProjectActions { public partial class ProjectDetails : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindProjectDetails(); } } public void BindProjectDetails() { string QueryStringID = Request.QueryString["id"]; if (QueryStringID == "") { QueryStringID = "0"; } string mySQLstring = "Select "; mySQLstring = mySQLstring + "Actions.ActionID, "; mySQLstring = mySQLstring + "Actions.ActionSummary, "; mySQLstring = mySQLstring + "ActionDetails.ActionDescription, "; mySQLstring = mySQLstring + "ActionDetails.ActionStartDate, "; mySQLstring = mySQLstring + "ActionDetails.ActionTargetCloseDate, "; mySQLstring = mySQLstring + "ActionDetails.ActionActualCloseDate, "; mySQLstring = mySQLstring + "ActionDetails.ActionStatus, "; mySQLstring = mySQLstring + "ActionDetails.ActionOwner, "; mySQLstring = mySQLstring + "ActionDetails.ActionLastModified, "; mySQLstring = mySQLstring + "ActionDetails.ActionUpdate "; mySQLstring = mySQLstring + "FROM ActionDetails "; mySQLstring = mySQLstring + "INNER JOIN Actions ON ActionDetails.ActionID = Actions.ActionID "; mySQLstring = mySQLstring + "INNER JOIN Projects ON ActionDetails.ProjectID = Projects.ProjectID "; mySQLstring = mySQLstring + "AND ActionDetails.ProjectID = " + QueryStringID + " "; mySQLstring = mySQLstring + "ORDER BY ActionID ASC"; string champeryConnection = WebConfigurationManager.ConnectionStrings["TheDatebase"].ConnectionString; //Error Handling for SQL Connection try { using (SqlConnection myConnection = new SqlConnection(champeryConnection)) { SqlCommand myCommand = new SqlCommand(mySQLstring, myConnection); // opens the connection to the database myConnection.Open(); DataTable projectData = new DataTable("ActionDetails"); SqlDataAdapter DataAdapter = new SqlDataAdapter(); DataAdapter.SelectCommand = myCommand; DataAdapter.Fill(projectData); ProjectDetailsGrid.DataSource = projectData; ProjectDetailsGrid.DataBind(); if(ProjectDetailsGrid.Rows.Count == 0){ Response.Redirect("\\ProjectActionsDetails/AddProjectActionsDetails.aspx?id=" + Request.QueryString["id"] + "&amp;name=" + Request.QueryString["name"] + ""); } } } //Write errors to Label 'Error' catch (Exception Err) { ErrorMessage.Text = Err.ToString(); SQLStatement.Text = mySQLstring; } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload