0
<asp:GridView ID="GridView1" class="datagrid" runat="server" AutoGenerateColumns="False" width="90%" Height="400px"
    OnRowCommand="GridView1_RowCommand" BackColor="White" 
    BorderColor="#CC9966" BorderStyle="None" 
    BorderWidth="1px" CellPadding="4">
    <Columns>
        <asp:TemplateField HeaderText="File" ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" 
                    CausesValidation="False" 
                    CommandArgument='<%# Eval("File") %>'
                    CommandName="Download" Text='<%# Eval("File") %>' 
                    onclick="LinkButton1_Click"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Size" HeaderText="Size in Bytes" />
        <asp:BoundField DataField="Type" HeaderText="File Type" />
    </Columns>
    <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" 
        ForeColor="#FFFFCC" />
    <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" 
        HorizontalAlign="Center" />
    <RowStyle BackColor="White" ForeColor="#330099" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" 
        ForeColor="#663399" />
    <SortedAscendingCellStyle BackColor="#FEFCEB" />
    <SortedAscendingHeaderStyle BackColor="#AF0101" />
    <SortedDescendingCellStyle BackColor="#F6F0C0" />
    <SortedDescendingHeaderStyle BackColor="#7E0000" />
</asp:GridView>

我有这个下载功能和上传我想包括一个下载验证码,如果文本框中的字符不正确,将有一个文本框和按钮下载将被禁用。

请注意,在文件部分我有链接按钮,使用户能够下载文件

4

3 回答 3

0

通过这种方式,我们可以动态禁用或启用链接按钮或任何其他控件

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {  
      GridView1.EditIndex = e.NewEditIndex;
      BindGrid();
      /*if (<condtition)
       * {
       * */
      GridView1.Columns[3].Visible = false;

      // * }  
    }

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
  //make it again visible 
   GridView1.Columns[3].Visible = true;

  // code to edit the rows
}
于 2013-09-11T05:46:32.207 回答
0

试试下面的代码,应该写在文件后面的代码中:

protected void GrivView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    LinkButtton lbtn = new LinkButtton();
    lbtn = (LinkButton)e.Row.FindControl("LinkButton1"); 
    lbtn.Enable = false;
}
于 2013-09-10T07:09:51.497 回答
0

我觉得这行代码就够了

 ((LinkButton)e.Row.Cells[1].Controls[0]).Visible = false;
于 2013-09-11T05:40:40.597 回答