By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,222 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,222 IT Pros & Developers. It's quick & easy.

datagrid editcommand question

P: n/a
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?
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I solved the problem by moving the code into the
ItemDataBound event like so:

[ code ]
If e.Item.ItemType = ListItemType.EditItem Then 'Check
whether or not to enable the CareType
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
End If
[ / code ]
-----Original Message-----
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 pagefor 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?
.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.