Вопрос

I've a ASP.NET GridView with the following data:

enter image description here

Rows will be disable OnRowDataBound based on the value on column3.

GridView :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
        onrowdatabound="GridView1_RowDataBound1">
        <Columns>
            <asp:TemplateField HeaderText="Column1">
                <ItemTemplate>
                    <asp:HyperLink ID="hyperlink" runat="server" Text='<% #Eval("Dosage") %>' NavigateUrl='<% #Eval("Dosage") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Column2">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<% #Eval("Drug") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Column3">
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<% #Eval("Patient") %>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Column4">
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<% #Eval("Date") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

RowDataBound :

protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label a = e.Row.FindControl("Label3") as Label;
        if (a.Text == "Sam")
        {
            e.Row.Enabled = false;
            e.Row.Cells[0].Enabled = true;
        }
    }
}

however, I want column1 always enable, hyperlink in column1 should always clickable.

I've tried get the cells and enabled it, but it is not working.

kindly advise what is the workaround for the issue above.

Это было полезно?

Решение

You can do this by enable/disable particular cell.

  protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label a = e.Row.FindControl("Label3") as Label;
        if (a.Text == "Sam")
        {

            e.Row.Cells[0].Enabled = true;
            e.Row.Cells[1].Enabled = false;
            e.Row.Cells[2].Enabled = false;
            e.Row.Cells[3].Enabled = false;

        }
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top