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;
}
}
Comments
Anonymous
October 15, 2008
Thank you for another good example. Keep them coming :-)Anonymous
October 15, 2008
Thank you for another good example. Keep them comming :-)Anonymous
October 21, 2008
Can we show a custom lookup for a field whose AllowEdit Property is set to No at the AX table level???? please helpAnonymous
January 22, 2011
Hi Friends! I am having a trouble, please guide me as I am strucked and cannot work further... I am having a form on EP which have the the dataSet from AX. Form is opened in Insert Mode. This form is of "Leave Request". I need to perform some action on the basis of some values. All the fields on the form are AxBoundFields used in AxGroups. For example I want to calculate the date difference between the "Leave Start Date" and "Leave End Date". Should I need to attach the event with "OnDataChanged" event of "Leave End Date" AxDataBound field? I am doing bt it is not effecting. Secondly, there is a AxCheckBoundField, I need to hide/unhide some AxBoundFields on the basis of that AxCheckBoundField. I attached the event , it is hiding and unhiding correctly bt the problem is when the event is fired, all the values in AxBoundField are lost.... I am not understanding, what's happening.. Please reply me as soon as possible... bcz it is pending my whole work Remember, I am setting the page as Insert Mode in Page_load event. Thanks in Advance. Ehtasham. ehtashamrahman@gmail.com