0

I have a gridview that displays a record with some linkbuttons.

What I want is when my ASP.NET ButtonStart is clicked enable the LinkButton in the Gridview

<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" />

I know how to disable it in 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;
            }

        }
  }

I believe you have to call RowDataBound from the BtnStart Click event but am not sure.

protected void btnStartTrans_Click(object sender, EventArgs e)
{
      //Enable lblClose in gridview
}
1
  • In the button click event, find control of lbclose and make its visible=true. Commented Aug 20, 2013 at 15:26

1 Answer 1

2

Just loop through the rows in the grid view and enable the lbClose in each row, like this:

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;
            }
        }            
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.