<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>
我有这个下载功能并上传 我想要包含一个下载验证码,如果文本框中的字符不正确,将会有一个文本框和按钮下载将被禁用。
请注意,在文件部分我有链接按钮,用户可以下载文件
答案 0 :(得分:0)
尝试下面的代码,应该用文件后面的代码编写:
protected void GrivView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButtton lbtn = new LinkButtton();
lbtn = (LinkButton)e.Row.FindControl("LinkButton1");
lbtn.Enable = false;
}
答案 1 :(得分:0)
我认为这行代码足够
((LinkButton)e.Row.Cells[1].Controls[0]).Visible = false;
答案 2 :(得分:0)
通过这种方式,我们可以动态地禁用或启用linkbutton或任何其他控件
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
}