Disabling a field when editing an existing record in a Datagrid

M

Mark Perona

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
 
A

Alex K

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>
 
D

Duray AKAR

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">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top