Disabling Bound Fields through code

You can make a bound field as read only or hide the Lookupbutton of the bound field through code in the page load event.

For example

...

AxBoundField boundField = AxGridView1.Columns[i] as AxBoundField;

boundField.ReadOnly = true;

...

 

or

 

...

AxBoundField boundField = AxGridView1.Columns[i] as AxBoundField;

boundField.LookupButtonDisplaySettings = LookupButtonDisplaySettings.Never;

...

 

If they do want to hide the lookup for specific rows, then they should use a  template field instead of the AxBoundField. For example ,

 

 In the below code DataSet Name is DemoSet, Table Name is Table1 and FieldName is AccountNum

asp:TemplateField ConvertEmptyStringToNull="False"

            HeaderText="<%$ AxLabel:@SYS1996 %>" SortExpression="AccountNum">

            <EditItemTemplate>

                <asp:TextBox ID="TextBox1" runat="server"

   Columns="<%$ AxDataSet:DemoSet.Table1.AccountNum.DisplayLength %>"

                    Enabled="<%$ AxDataSet:DemoSet.Table1.AccountNum.AllowEdit %>"

                    MaxLength="<%$ AxDataSet:DemoSet.Table1.AccountNum.StringSize %>"

                    Text='<%# Bind("AccountNum") %>'></asp:TextBox>

                <dynamics:AxLookup ID="AxLookup1" runat="server" DataLookupField="AccountNum"

                    DataSet="DemoSet" DataSetView="Table1" TargetControlId="TextBox1"

      Visible="<%$ AxDataSet:DemoSet.Table1.AccountNum.AllowEdit %>">

                </dynamics:AxLookup>

            </EditItemTemplate>

            <ItemTemplate>

                <asp:Label ID="Label1" runat="server" Text='<%# Bind("AccountNum") %>'></asp:Label>

            </ItemTemplate>

        </asp:TemplateField>

Code Behind to hide the lookup control conditionally and disable the cell

protected void AxGridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row != null && e.Row.RowType == DataControlRowType.DataRow)

        {

       /* disable the thrid column which displays accountnum and hide the lookup if the second field value is 1

            DataSetViewRow dataRow = (DataSetViewRow)e.Row.DataItem;

  bool isInternalProject = dataRow.GetFieldValue("Field2").ToString() == "1";

            if (isInternalProject)

            {

                Control c = e.Row.Cells[2].FindControl("AxLookup1");

                if ( c!= null)

                    c.Visible = false;

                e.Row.Cells[2].Enabled = false;

            }

        }