2013-08-20 2 views
0

일부 링크 버튼이있는 레코드를 표시하는 gridview가 있습니다. 내 ASP.NET ButtonStart가 GRIDVIEWASP.NET 버튼을 클릭했을 때 Gridview에서 Linkbutton을 활성화하십시오.

<asp:GridView ID="gvData" runat="server" CellPadding="4" ForeColor="#333333" 
GridLines="None" Width="688px" AllowPaging="True" AllowSorting="True"AutoGenerateColumns="False" 
OnRowCommand="gvData_RowCommand" 
OnRowDataBound="gvData_RowDataBound"> 
<AlternatingRowStyle BackColor="White" ForeColor="#284775" /> 
<Columns> 
     <asp:BoundField DataField="Id" HeaderText="ID" SortExpression="Id"> 
     <ItemStyle HorizontalAlign="Center" /> 
     </asp:BoundField>       
    <asp:BoundField DataField="Received" HeaderText="Received" SortExpression="Received" 
     ReadOnly="true"> 
     <ItemStyle HorizontalAlign="Center" /> 
     </asp:BoundField>            
    <asp:TemplateField ShowHeader="False"> 
    <ItemTemplate> 
      <asp:LinkButton ID="lbClose" runat="server" CausesValidation="False"  CommandName="CloseClicked" 
      OnClick="CloseClick_Click">Close</asp:LinkButton>                
    </ItemTemplate>        
     <FooterStyle HorizontalAlign="Center" /> 
    <ItemStyle HorizontalAlign="Center" /> 
    </asp:TemplateField> 
    </Columns>     
    </asp:GridView> 


    <asp:button runat="server" text="Start" ID="btnStart" /> 

에서의 LinkButton을 가능하게 클릭 할 때

는 내가 원하는 내가 RowDataBound에 사용하지 않도록 설정하는 방법을 알고있다.

protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 


     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      LinkButton lbClose = (LinkButton)e.Row.Cells[5].FindControl("lbClose"); 

      if (lbClose == null) 
      { 
       return; 
      } 


      var lblReceive = (Label)e.Row.FindControl("lblReceive ");    


      if (lblReceive .Text == "" && !IsPostBack) 
      { 
       lbClose.Enabled = true; 
       lbEdit.Enabled = true; 
       lbDelete.Enabled = true; 
      } 

     } 
    } 

나는 BtnStart Click 이벤트에서 RowDataBound를 호출해야한다고 생각하지만 확실치 않습니다.

protected void btnStartTrans_Click(object sender, EventArgs e) 
{ 
     //Enable lblClose in gridview 
} 
+0

는 lbclose의 제어를 발견하고 그것 = 눈에 보이는 사실 확인하십시오. – Sasidharan

답변

2

단지의 격자보기에서 행을 통해 루프와 같은 각 행의 lbClose을 활성화 : 버튼 클릭 이벤트에서

protected void btnStartTrans_Click(object sender, EventArgs e) 
{ 
    // Loop through all rows in the grid 
    foreach (GridViewRow row in grid.Rows) 
    { 
     // Only look for `lbClose` in data rows, ignore header and footer rows, etc. 
     if (row.RowType == DataControlRowType.DataRow) 
     { 
      // Find the `lbClose` LinkButton control in the row 
      LinkButton theLinkButton = (LinkButton)row.FindControl("lbClose"); 

      // Make sure control is not null 
      if(theLinkButton != null) 
      { 
       // Enable the link button 
       theLinkButton.Enabled = true; 
      } 
     }    
    } 
} 
관련 문제