B
bill yeager
I'm doing an inline edit of an Admin table using the
Datagrid. There are three columns in my Admin table. I
want to dynamically disable the corresponding "CareType"
field (see below) in the grid if the record is part of an
existing relationship, so the user can't update it.
The "CareTypeID" field is the key and is invisible to the
user.
Here is the db table columns:
CareTypeID
CareType
CareTypeDesc
Here is my code in the DataGrid1.EditCommand event:
<code>
Dim intRecdsFnd As Integer
intRecdsFnd = ValidateChild.ValidateChildTable
("CallType", DataGrid1.DataKeys(e.Item.ItemIndex), CType
(Application("strDataSource"), String))
Dim txtCareType As TextBox = DirectCast
(e.Item.FindControl("txtCareType"), TextBox)
If intRecdsFnd = 0 Then
txtCareType.Enabled = True
Else
txtCareType.Enabled = False
End If
ViewState.Item("intRecdsFnd") = Convert.ToInt32
(intRecdsFnd)
DataGrid1.EditItemIndex = e.Item.ItemIndex
BindData()
</code>
When executing the following line above in order to
disable the field that I want,
<code>
Dim txtCareType As TextBox = DirectCast(e.Item.FindControl
("txtCareType"), TextBox)
</code>
the value comes back as "Nothing"!
Here is my corresponding code in the HTML of the aspx page
for the column:
<code>
<asp:TemplateColumn HeaderText="CareType">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.CareType") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtFtrCareType" Columns="20"
runat="server" MaxLength="30"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:TextBox id=txtCareType Columns="20"
runat="server" MaxLength="20" Text='<%# DataBinder.Eval
(Container, "DataItem.CareType") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator
id="Requiredfieldvalidator1" runat="server"
ControlToValidate="txtCareType" ErrorMessage="CareType is
required!"
CssClass="invalid" Font-Bold="True" />
</EditItemTemplate>
</asp:TemplateColumn>
</code>
Just to see, I get a hit if I use an ID value for the
Label in the ItemTemplate, but I don't get a hit when
trying to get the value from the EditItemTemplate.
However, the Label value doesn't do me any good, since I
need to disable the field when the user presses the Edit
command.
I tried moving the following line:
<code>
Dim txtCareType As TextBox = DirectCast(e.Item.FindControl
("txtCareType"), TextBox)
</code>
after the BindData() routine (which executes the
DataGrid1.ItemDataBound event), but still didn't help.
How come I am not getting a hit on the ID value of the
textbox during the EditCommand?
Datagrid. There are three columns in my Admin table. I
want to dynamically disable the corresponding "CareType"
field (see below) in the grid if the record is part of an
existing relationship, so the user can't update it.
The "CareTypeID" field is the key and is invisible to the
user.
Here is the db table columns:
CareTypeID
CareType
CareTypeDesc
Here is my code in the DataGrid1.EditCommand event:
<code>
Dim intRecdsFnd As Integer
intRecdsFnd = ValidateChild.ValidateChildTable
("CallType", DataGrid1.DataKeys(e.Item.ItemIndex), CType
(Application("strDataSource"), String))
Dim txtCareType As TextBox = DirectCast
(e.Item.FindControl("txtCareType"), TextBox)
If intRecdsFnd = 0 Then
txtCareType.Enabled = True
Else
txtCareType.Enabled = False
End If
ViewState.Item("intRecdsFnd") = Convert.ToInt32
(intRecdsFnd)
DataGrid1.EditItemIndex = e.Item.ItemIndex
BindData()
</code>
When executing the following line above in order to
disable the field that I want,
<code>
Dim txtCareType As TextBox = DirectCast(e.Item.FindControl
("txtCareType"), TextBox)
</code>
the value comes back as "Nothing"!
Here is my corresponding code in the HTML of the aspx page
for the column:
<code>
<asp:TemplateColumn HeaderText="CareType">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.CareType") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtFtrCareType" Columns="20"
runat="server" MaxLength="30"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:TextBox id=txtCareType Columns="20"
runat="server" MaxLength="20" Text='<%# DataBinder.Eval
(Container, "DataItem.CareType") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator
id="Requiredfieldvalidator1" runat="server"
ControlToValidate="txtCareType" ErrorMessage="CareType is
required!"
CssClass="invalid" Font-Bold="True" />
</EditItemTemplate>
</asp:TemplateColumn>
</code>
Just to see, I get a hit if I use an ID value for the
Label in the ItemTemplate, but I don't get a hit when
trying to get the value from the EditItemTemplate.
However, the Label value doesn't do me any good, since I
need to disable the field when the user presses the Edit
command.
I tried moving the following line:
<code>
Dim txtCareType As TextBox = DirectCast(e.Item.FindControl
("txtCareType"), TextBox)
</code>
after the BindData() routine (which executes the
DataGrid1.ItemDataBound event), but still didn't help.
How come I am not getting a hit on the ID value of the
textbox during the EditCommand?