I'm trying to get RadGrid to conditionally hide or disable a field when it is in edit mode based on the value of another field.
I have been able to get this to work when the grid displays the list of items, but once the grid enters edit mode, the columns display ...
I am using OnItemDataBound to successfully conditionally display during the initial load, but setting the items when the user clicks a row to get it into batch mode is not working.
I'm also trying to set the tab order when I go into edit mode, for some reason, the grid throws the cursor to the 2nd column ...
Note: PValue and CValue and in GridTemplateColumns, as is CardStatus.
public void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
foreach (GridDataItem item in RadGrid1.Items)
{
string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
string BoundColumnValue2 = item["CValue"].Text;
TextBox txtbx = (TextBox)item.FindControl("CardStatus");
Label numlb = (Label)item.FindControl("CardValue");
if (txtbx.Text.Equals("True"))
{
txtbx.ForeColor = Color.Red;
numlb.Enabled = false;
numlb.BackColor = Color.Yellow;
numlb.ForeColor = Color.Red;
//Just testing to see if it would evaluate
}
else
{
txtbx.ForeColor = Color.Beige;
}
//string TemplateColumnValue = lb.Text;// accessing Label Text.
}
foreach (GridEditableItem item in RadGrid1.EditItems)
{
string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
string BoundColumnValue2 = item["CValue"].Text;
TextBox txtbx = (TextBox)item.FindControl("CardStatus");
if (txtbx.Text.Equals("True"))
{
txtbx.ForeColor = Color.Red;
//numTxt.BackColor = Color.Yellow;
//numTxt.ForeColor = Color.Red;
}
else
{
txtbx.ForeColor = Color.Beige;
}
}
}
I just need to be able to selectively prevent data entry in a column
The ASPX source is below:
<
telerik:GridTemplateColumn
ColumnEditorID
=
"CValue"
DataField
=
"CValue"
HeaderText
=
"Card"
UniqueName
=
"CValue"
ItemStyle-Width
=
"75px"
HeaderStyle-Width
=
"75px"
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"CValue"
Width
=
"50px"
AllowOutOfRangeAutoCorrect
=
"false"
runat
=
"server"
MaxLength
=
"1"
MaxValue
=
"1"
NumberFormat-DecimalDigits
=
"0"
Text='<%# Bind("CValue") %>'></
telerik:RadNumericTextBox
>
<
asp:RequiredFieldValidator
runat
=
"server"
ControlToValidate
=
"CValue"
ErrorMessage="<br />Required (0-1 Only)!" SetFocusOnError="true"></
asp:RequiredFieldValidator
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"CValue"
Width
=
"50px"
runat
=
"server"
Text='<%# Bind("CValue") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"DateEdited"
ReadOnly
=
"true"
Visible
=
"false"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter DateEdited column"
HeaderText
=
"DateEdited"
SortExpression
=
"DateEdited"
UniqueName
=
"DateEdited"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"CardStatus"
DataField
=
"CardStatus"
ItemStyle-Width
=
"50px"
HeaderStyle-Width
=
"50px"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"CardStatus"
Width
=
"10px"
runat
=
"server"
Text='<%# Bind("CardStatus") %>'></
asp:TextBox
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:TextBox
ID
=
"CardStatus"
Width
=
"10px"
runat
=
"server"
Text='<%# Bind("CardStatus") %>'></
asp:TextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
></
PagerStyle
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
</
telerik:RadGrid
>
Any help / workarounds would be appreciated ... again, "just" need to
prevent editing in the CValue column when the CardStatus value is true
(bit field) ... using batch mode (using another solution isn't an option
now).
Also, the issue with the tab order being messed up is particularly frustrating ... any hints on that one?
Thanks
Larry
(sorry , this is cross-posted elsewhere, but am a bit desperate right now).