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

Disabling a field when editing an existing record in a Datagrid

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.