2011-01-17 3 views
3

코드 뒤에 채워진 격자보기가 있습니다. 이 GridView에서 AutoGenerateEditButton을 활성화했지만 이제 인라인 편집을 활성화하는 방법을 찾을 수 없습니다.GridView의 인라인 편집

나는 샘플을 찾고 유용한 것을 찾지 못했다. 다음은 내 ASPX 페이지의 사본과 그 뒤에있는 코드입니다. 당신이의 GridView를 사용하여 의무가없는 경우에, 나는 강하게의 ListView를 사용하는 것이 좋습니다

ProjectDetails.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProjectDetails.aspx.cs" Inherits="ProjectActions.ProjectDetails" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div>  
     <asp:GridView ID="ProjectDetailsGrid" 
      runat="server" 
      AutoGenerateColumns="False" 
      AutoGenerateEditButton="True" CellPadding="3" 
      GridLines="Horizontal" BackColor="White" BorderColor="Black" 
      BorderStyle="Solid" BorderWidth="6px"> 
      <AlternatingRowStyle BackColor="#F7F7F7" /> 
      <Columns> 
      <asp:BoundField HeaderText ="ID" DataField="ActionID" /> 
      <asp:BoundField HeaderText ="Summary" DataField="ActionSummary" /> 

      <asp:BoundField HeaderText ="Description" DataField="ActionDescription" /> 
      <asp:BoundField HeaderText ="Start Date" DataField="ActionStartDate" /> 
      <asp:BoundField HeaderText ="Target Close Date" DataField="ActionTargetCloseDate" /> 
      <asp:BoundField HeaderText ="Actual Close Date" DataField="ActionActualCloseDate" /> 
      <asp:BoundField HeaderText ="Status" DataField="ActionStatus" /> 
      <asp:BoundField HeaderText ="Owner" DataField="ActionOwner" /> 
      <asp:BoundField HeaderText ="Last Modified" DataField="ActionLastModified" /> 
      <asp:BoundField HeaderText ="Action Update" DataField="ActionUpdate" /> 
      </Columns> 
      <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> 
      <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /> 
      <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /> 
      <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /> 
      <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /> 
      <SortedAscendingCellStyle BackColor="#F4F4FD" /> 
      <SortedAscendingHeaderStyle BackColor="#5A4C9D" /> 
      <SortedDescendingCellStyle BackColor="#D8D8F0" /> 
      <SortedDescendingHeaderStyle BackColor="#3E3277" /> 
     </asp:GridView> 
    </div> 
    </form> 
    <asp:Label ID="ErrorMessage" runat="server" Text=""></asp:Label> 
    <br /> 
    <br /> 
    <asp:Label ID="SQLStatement" runat="server" Text=""></asp:Label> 
</body> 
</html> 

ProjectDetails.aspx.cs

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"] + "&name=" + Request.QueryString["name"] + ""); 
        } 

       } 

      } 
      //Write errors to Label 'Error' 
      catch (Exception Err) 
      { 
       ErrorMessage.Text = Err.ToString(); 
       SQLStatement.Text = mySQLstring; 
      } 
     } 
    } 
} 

답변

관련 문제