473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Disabling a field when editing an existing record in a Datagrid

I created an ASP.net form with an editable datagrid on it. I can
create new records, and update and delete existing records. The
problem I have is that I want a field in the grid to be editible when
I'm editing a new record, but disabled when editable an existing
record. Any ideas

Mark
Nov 17 '05 #1
2 1720
try it it should work
<asp:TemplateColumn HeaderText=" Comments">
<HeaderStyle HorizontalAlign="Center" Width="130px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label ID="lblNote" text='<%#Container.DataItem("Note")%>'
runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtNote" Runat="server" ReadOnly="True"
text='<%#Container.DataItem("Note")%>' Rows="2" TextMode="MultiLine"
MaxLength="250">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>

"Mark Perona" <mp*****@earthlink.net> wrote in message
news:51**************************@posting.google.c om...
I created an ASP.net form with an editable datagrid on it. I can
create new records, and update and delete existing records. The
problem I have is that I want a field in the grid to be editible when
I'm editing a new record, but disabled when editable an existing
record. Any ideas

Mark

Nov 17 '05 #2
Where do you display the fields to add a new record ?

You cannot edit a new record, you add it, then it becomes
an existing record, and then you Edit the existing
record...

So I am assuming that you are using a DataSet, Adding the
record to the DataTable before you send it to the
database, displaying in the DataGrid and then Commiting it
to the database when the user confirms.

in this case you can check the RowState of the currentrow
of the DataTable to check if it is a new record or not.
LEts say you have a DataKeyField ID in dtNotes datatable...
You can put in the codebehind

protected DataSet dsNotes;
protected DataTable dtNotes ;

public bool CheckNew(object myKey)
{

}

<asp:TextBox ID="txtNote" Runat="server" ReadOnly='<%
#CheckNew(Container.DataItem("ID"))%>'
text='<%#Container.DataItem("Note")%>' Rows="2"
TextMode="MultiLine"
MaxLength="250">
-----Original Message-----
I created an ASP.net form with an editable datagrid on it. I cancreate new records, and update and delete existing records. Theproblem I have is that I want a field in the grid to be editible whenI'm editing a new record, but disabled when editable an existingrecord. Any ideas

Mark
.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a...
7
by: astro | last post by:
Anyone have suggestions on where to troubleshoot this error? Background: -Access 2k v. 9.0.6926 sp3 - front and backend on production server (wiindows 2k) -accessed via Citrix -front-end is...
2
by: MIG | last post by:
Is there a way that, when using a single or continuous form which allows additions and edits, I can detect when I am entering a new record (eg moved on to *) rather than editing an existing one? ...
2
by: Mike P | last post by:
I have a datagrid with a 'Delete' column that the user can click on to delete a row in the datagrid. I thought that I would need to have some kind of error handling in case somebody goes into the...
2
by: jaYPee | last post by:
i'm wondering how can i update the current record in datagrid while still editing the record. cause i have a checkbox in my datagrid and i want to save the record before changing the value of this...
6
by: HS1 | last post by:
Hello I have a table in Access Database. This table has a AutoNumber field. I use a DataGrid to show that table When I insert a new record in for this table using a DataGrid, there is a...
3
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is...
8
by: sara | last post by:
I have a table where a few of the users entered vendor names ALL IN UPPER CASE. I have created forms to edit the data, but I can't seem to allow changing JOE SMITH to Joe Smith. What to I have...
0
by: hanusoft | last post by:
This is an example of editing in DataGrid and Default Paging http://www.hanusoftware.com Html Design Code : - <asp:DataGrid id="DataGrid1" DataKeyField="id" runat="server" Height="224px"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.