Welcome to MSDN Blogs Sign in | Join | Help

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;

            }

        }

 

Published Wednesday, October 15, 2008 7:12 PM by meysun
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Disabling Bound Fields through code

Thursday, October 16, 2008 1:51 AM by pagermark

Thank you for another good example. Keep them coming :-)

# re: Disabling Bound Fields through code

Thursday, October 16, 2008 1:51 AM by pagermark

Thank you for another good example. Keep them comming :-)

# re: Disabling Bound Fields through code

Tuesday, October 21, 2008 8:00 AM by Chandra Shekhar Mantha

Can we show a custom lookup for a field whose AllowEdit Property is set to No at the AX table level????

please help

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker