2013-11-25 2 views
0

현재 컬렉션에 바인딩 된 gridview가 있습니다. 'RowCreated'이벤트 내에서 html (특정 필드에 취소 선을 추가)을 조작하고 있습니다.Gridview를 정렬 한 후 왜 rowcreated 이벤트가 시작되지 않습니까?

이 모든 페이지로드에 잘 작동하지만 열을 정렬 할 때마다 RowCreated 이벤트가 발생하지 않는 것 같습니다.

어떻게 수정합니까?

편집 : 여기에 내가 여기

protected void gvResults_RowCreated(object sender, GridViewRowEventArgs e) 
     { 
      if (e.Row.RowType == DataControlRowType.DataRow) 
      { 
       if (e.Row.DataItem != null) 
       { 
        Property currentProperty = (Property)e.Row.DataItem; 

        e.Row.Attributes.Add("id", currentProperty.Id.ToString()); 

        Document propertyDoc = new Document(currentProperty.Id); 

        if (currentProperty.Price == 0) 
        { 
         e.Row.Cells[5].Controls.Clear(); 
         e.Row.Cells[5].Controls.Add(new Literal() { Text = "N/A" }); 
        } 
        if (propertyDoc.getProperty("floorPlan").Value == null || propertyDoc.getProperty("floorPlan").Value.ToString() == "") 
        { 
         e.Row.Cells[6].Controls.Clear(); 
         e.Row.Cells[6].Controls.Add(new Literal() { Text = "View" }); 
        } 
        if (propertyDoc.getProperty("propertyImage").Value == null || propertyDoc.getProperty("propertyImage").Value.ToString() == "") 
        { 
         e.Row.Cells[7].Controls.Clear(); 
         e.Row.Cells[7].Controls.Add(new Literal() { Text = "View" }); 
        } 

        if (currentProperty.Reserved == true) 
        { 
         e.Row.ForeColor = System.Drawing.ColorTranslator.FromHtml("#999999"); 
         e.Row.Cells[1].Text = currentProperty.DevelopmentName; 
         e.Row.Cells[2].Text = currentProperty.LocationDisplayText; 
         e.Row.Cells[3].Text = currentProperty.PropertyTypeName; 
         e.Row.Cells[4].Text = currentProperty.BedroomsDisplayText; 

         e.Row.Cells[5].Controls.Clear(); 
         e.Row.Cells[5].Controls.Add(new Literal() { Text = "RESERVED" }); 
         //e.Row.Cells[6].Controls.Clear(); 
         //e.Row.Cells[6].Controls.Add(new Literal() { Text = "<del>View</del>" }); 
         //e.Row.Cells[7].Controls.Clear(); 
         //e.Row.Cells[7].Controls.Add(new Literal() { Text = "<del>View</del>" }); 
        } 
        else if (currentProperty.Sold == true) 
        { 
         e.Row.ForeColor = System.Drawing.ColorTranslator.FromHtml("#999999"); 
         e.Row.Cells[1].Text = currentProperty.DevelopmentName; 
         e.Row.Cells[2].Text = currentProperty.LocationDisplayText; 
         e.Row.Cells[3].Text = currentProperty.PropertyTypeName; 
         e.Row.Cells[4].Text = currentProperty.BedroomsDisplayText; 

         e.Row.Cells[5].Controls.Clear(); 
         e.Row.Cells[5].Controls.Add(new Literal() { Text = "SOLD" }); 
         //e.Row.Cells[6].Controls.Clear(); 
         //e.Row.Cells[6].Controls.Add(new Literal() { Text = "<del>View</del>" }); 
         //e.Row.Cells[7].Controls.Clear(); 
         //e.Row.Cells[7].Controls.Add(new Literal() { Text = "<del>View</del>" }); 
        } 
        else if (currentProperty.Released == true) 
        { 
         e.Row.ForeColor = System.Drawing.ColorTranslator.FromHtml("#999999"); 
         e.Row.Cells[1].Text = currentProperty.DevelopmentName; 
         e.Row.Cells[2].Text = currentProperty.LocationDisplayText; 
         e.Row.Cells[3].Text = currentProperty.PropertyTypeName; 
         e.Row.Cells[4].Text = currentProperty.BedroomsDisplayText; 

         e.Row.Cells[5].Controls.Clear(); 
         e.Row.Cells[5].Controls.Add(new Literal() { Text = "TO BE RELEASED" }); 
         //e.Row.Cells[6].Controls.Clear(); 
         //e.Row.Cells[6].Controls.Add(new Literal() { Text = "<del>View</del>" }); 
         //e.Row.Cells[7].Controls.Clear(); 
         //e.Row.Cells[7].Controls.Add(new Literal() { Text = "<del>View</del>" }); 
        } 
       } 
      } 
     } 

는 프론트 엔드 코드입니다 .. 내 RowCreated 방법으로하고 있어요 무엇 :

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FullSearchResults.ascx.cs" Inherits="MyControls.FullSearchResults" %> 
<div id="search-results"> 
    <asp:GridView ID="gvResults" runat="server" AutoGenerateColumns="false" DataSourceID="odsProperties" 
     AllowSorting="true" Width="700px" OnRowCommand="gvResults_RowCommand" OnRowCreated="gvResults_RowCreated"> 
     <HeaderStyle CssClass="gv-header" ForeColor="#ffffff" /> 
     <RowStyle BackColor="White" ForeColor="#333333" /> 
     <AlternatingRowStyle BackColor="#e6e6e6" ForeColor="#333333" /> 
     <Columns> 
      <asp:BoundField DataField="Plot" HeaderText="Plot" SortExpression="Plot" /> 
      <asp:TemplateField HeaderText="Development" SortExpression="Development"> 
       <ItemTemplate> 
        <%# Eval("DevelopmentName").ToString() %> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Location" SortExpression="Location"> 
       <ItemTemplate> 
        <%# Eval("LocationDisplayText").ToString() %> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Type" SortExpression="Type"> 
       <ItemTemplate> 
        <%# Eval("PropertyTypeName").ToString() %> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Beds" SortExpression="Bedrooms"> 
       <ItemTemplate> 
        <%# Eval("BedroomsDisplayText").ToString() %> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Price" SortExpression="Price"> 
       <ItemTemplate> 
        <%# Eval("PriceDisplayText").ToString() %> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Plans"> 
       <ItemTemplate> 
        <asp:LinkButton ID="btnViewFloorplans" runat="server" CommandName="View" Text="View" 
         CommandArgument='<%# (int)Eval("Id") %>' CssClass="view-floorplan" /> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Image"> 
       <ItemTemplate> 
        <asp:LinkButton ID="btnViewImage" runat="server" CommandName="View" Text="View" 
         CommandArgument='<%# (int)Eval("Id") %>' CssClass="view-floorplan" /> 
       </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 
    <asp:ObjectDataSource ID="odsProperties" runat="server" TypeName="MyControls.DataAccess" 
     SelectMethod="GetSearchResultsForAllDevelopments" SortParameterName="_sortExpression"> 
     <SelectParameters> 
      <asp:QueryStringParameter Name="_county" QueryStringField="loc" Type="Int16" DefaultValue="-1" /> 
      <asp:QueryStringParameter Name="_bedrooms" QueryStringField="rooms" Type="Int16" 
       DefaultValue="-1" /> 
      <asp:QueryStringParameter Name="_price" QueryStringField="price" Type="Int16" DefaultValue="-1" /> 
      <asp:QueryStringParameter Name="_propertyType" QueryStringField="type" Type="Int16" 
       DefaultValue="-1" />    
     </SelectParameters> 
    </asp:ObjectDataSource>  
</div> 
+0

'RowCreated'가 매번 트리거됩니다. 그래서 우리에게 몇 가지 코드를 보여줘야합니다. –

+0

클라이언트 측 정렬 기능이 있습니까? 왜냐하면 Tim이 말했듯이, RowCreated는 모든 게시물을 다시 발생시키기 때문입니다. –

+0

하지만 모든 포스트 백이 발생하면 반드시 내 코드가 실행되어야합니다. 현재로서는 보이지 않습니다. – alimac83

답변

1

수행 할 RowCreated 이벤트 대신 RowDataBound 이벤트를 사용하는 것을 고려 HTML 사용자 정의 (즉, 특정 필드에 취소 선 (strike-through) 추가).

RowDataBound 이벤트는 그리드보기가 리바운드 될 때마다 호출됩니다 (예 : GridView.DataBind()). RowDataBound 이벤트는 행에 렌더링되는 실제 데이터에 대한 액세스도 가지므로 대부분의 행 변경은 해당 행에 포함 된 데이터와 관련되기 때문에 일반적으로 사람들이 원하는 것입니다.


RowCreated는 행 (격자의 마크 업에서 정의 즉 컨트롤) 구조를 구축 주로 우려 페이지 Init 포스트 뒤에 소성한다.


RowDataBound

RowCreated는 이벤트에 만들어 대조군으로 데이터 소스로부터 데이터를 바인딩과 관련된 기본이다.

+0

감사합니다. Karl하지만 실제로 이미 시도 했었습니다. 작동하지 않았습니다. 이 중 하나가 객체 데이터 소스도 사용하고 있다는 사실과 관련이 있는지 궁금합니다. – alimac83

관련 문제