473,503 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid editcommand question

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
1 1679
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5958
by: Richard Roche | last post by:
Is it possible to use a drop combo instead of a text box when using the EditCommand in the Datagrid? Many table columns are bound to 'lookup' tables, user's don't care about the foreign keys,...
0
2253
by: Chad Folden | last post by:
I can't figure out how to use the EditCommand for the nested datagrid .. HELP PLEASE ;-) It works perfectly for the parent datagrid, but will not display, even though the EditCommand event is...
0
1289
by: Dan C Douglas | last post by:
I have created a hierarchical datagrid that consists of 1 datagrid nested insde of another datagrid. More technically it is actually 1 User control that contains a datagrid. I add this user control...
0
1044
by: Mike | last post by:
I've got an app with a DataTable that gets passed around and modified by datagrids on 3 different asp.net pages. Not all columns need to be displayed, but I need them all in the datagrid so I can...
7
4201
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
1
4278
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
4
3476
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
1
1220
by: MrMike | last post by:
I have a sub named Bind("") which binds my a datagrid on my webform. In order to enter edit mode and edit records on this datagrid, I must make a call to Bind("") either before or after I place...
5
2028
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.