472,334 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Making datagrid partially editable

Hi,
I have a datagrid databound to a SQL query. I'd like to allow editing of
some columns but not all. Is there a way to turn off the conversion of the
datagrid cells to textboxes for some columns when the Edit button is
pressed?
Thank you,
Stephan.

Nov 18 '05 #1
4 1715
Convert the columns to templates and the columns you don't want to be
editable, change the edit item template control from a textbox to a label.

--Morgan

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC3EA79F.E60C%sb***@niaid.nih.gov...
Hi,
I have a datagrid databound to a SQL query. I'd like to allow editing of
some columns but not all. Is there a way to turn off the conversion of the
datagrid cells to textboxes for some columns when the Edit button is
pressed?
Thank you,
Stephan.

Nov 18 '05 #2
Thanks for the suggestion. If I simply add a template column with a label, I
do get a non-editable column. Unfortunately, that doesn't prevent the
EditCommandColumn to generate all columns contained in my databinder and
making them editable. In the example below, the "Description" column is
duplicated with one editable and the other (the itemtemplate one) not. Am I
going to have to modify the SQL query or is there a way to exclude the
Description column from the EditCommandColumn?
<asp:DataGrid id="ByJob" AutoGenerateColumns="true"
OnEditCommand="ByJob_Edit" OnCancelCommand="ByJob_Cancel"
OnUpdateCommand="ByJob_Update" runat="server">
<HeaderStyle backcolor="Black" forecolor="White" font-bold="True"
horizontalalign="Left" />
<Columns>
<asp:EditCommandColumn EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
ItemStyle-Wrap="false"
/>

<asp:TemplateColumn>

<HeaderTemplate>
<b> Description </b>
</HeaderTemplate>

<ItemTemplate>
<asp:Label
Text='<%# DataBinder.Eval(Container.DataItem,
"Description") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Thanks,
Stephan.

in article ut**************@TK2MSFTNGP09.phx.gbl, Morgan at
ab**@senditon.com wrote on 1/29/04 12:22 PM:
Convert the columns to templates and the columns you don't want to be
editable, change the edit item template control from a textbox to a label.

--Morgan

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC3EA79F.E60C%sb***@niaid.nih.gov...
Hi,
I have a datagrid databound to a SQL query. I'd like to allow editing of
some columns but not all. Is there a way to turn off the conversion of the
datagrid cells to textboxes for some columns when the Edit button is
pressed?
Thank you,
Stephan.



Nov 18 '05 #3
Not at all. My suggestion was to convert the existing column to a template
column. Once you do this, you have 2 different items to work with (right
click the grid, Edit Template), the Item Template and the EditItemTemplate.
The Item Template is the read-only portion, EditItem Template is what is
displayed when you set the edit item index. Example below.

After all this, I remember you can set the Read Only property on the column
in the designer, which should do the trick for you and is much easier to
implement. Hopefully that will give you what you need.

<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label id="LabelReadOnlyDisplayMode"
runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label id="LabelReadOnlyEditMode"
runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>

Morgan

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC3EEAD3.E7A9%sb***@niaid.nih.gov...
Thanks for the suggestion. If I simply add a template column with a label, I do get a non-editable column. Unfortunately, that doesn't prevent the
EditCommandColumn to generate all columns contained in my databinder and
making them editable. In the example below, the "Description" column is
duplicated with one editable and the other (the itemtemplate one) not. Am I going to have to modify the SQL query or is there a way to exclude the
Description column from the EditCommandColumn?
<asp:DataGrid id="ByJob" AutoGenerateColumns="true"
OnEditCommand="ByJob_Edit" OnCancelCommand="ByJob_Cancel"
OnUpdateCommand="ByJob_Update" runat="server">
<HeaderStyle backcolor="Black" forecolor="White" font-bold="True"
horizontalalign="Left" />
<Columns>
<asp:EditCommandColumn EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
ItemStyle-Wrap="false"
/>

<asp:TemplateColumn>

<HeaderTemplate>
<b> Description </b>
</HeaderTemplate>

<ItemTemplate>
<asp:Label
Text='<%# DataBinder.Eval(Container.DataItem,
"Description") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Thanks,
Stephan.

in article ut**************@TK2MSFTNGP09.phx.gbl, Morgan at
ab**@senditon.com wrote on 1/29/04 12:22 PM:
Convert the columns to templates and the columns you don't want to be
editable, change the edit item template control from a textbox to a label.
--Morgan

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC3EA79F.E60C%sb***@niaid.nih.gov...
Hi,
I have a datagrid databound to a SQL query. I'd like to allow editing of some columns but not all. Is there a way to turn off the conversion of the datagrid cells to textboxes for some columns when the Edit button is
pressed?
Thank you,
Stephan.


Nov 18 '05 #4
Got it! Thanks a lot.
Stephan.

in article ui**************@TK2MSFTNGP11.phx.gbl, Morgan at
ab**@senditon.com wrote on 1/29/04 7:34 PM:
Not at all. My suggestion was to convert the existing column to a template
column. Once you do this, you have 2 different items to work with (right
click the grid, Edit Template), the Item Template and the EditItemTemplate.
The Item Template is the read-only portion, EditItem Template is what is
displayed when you set the edit item index. Example below.

After all this, I remember you can set the Read Only property on the column
in the designer, which should do the trick for you and is much easier to
implement. Hopefully that will give you what you need.

<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label id="LabelReadOnlyDisplayMode"
runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label id="LabelReadOnlyEditMode"
runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>

Morgan

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC3EEAD3.E7A9%sb***@niaid.nih.gov...
Thanks for the suggestion. If I simply add a template column with a label,

I
do get a non-editable column. Unfortunately, that doesn't prevent the
EditCommandColumn to generate all columns contained in my databinder and
making them editable. In the example below, the "Description" column is
duplicated with one editable and the other (the itemtemplate one) not. Am

I
going to have to modify the SQL query or is there a way to exclude the
Description column from the EditCommandColumn?
<asp:DataGrid id="ByJob" AutoGenerateColumns="true"
OnEditCommand="ByJob_Edit" OnCancelCommand="ByJob_Cancel"
OnUpdateCommand="ByJob_Update" runat="server">
<HeaderStyle backcolor="Black" forecolor="White" font-bold="True"
horizontalalign="Left" />
<Columns>
<asp:EditCommandColumn EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
ItemStyle-Wrap="false"
/>

<asp:TemplateColumn>

<HeaderTemplate>
<b> Description </b>
</HeaderTemplate>

<ItemTemplate>
<asp:Label
Text='<%# DataBinder.Eval(Container.DataItem,
"Description") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Thanks,
Stephan.

in article ut**************@TK2MSFTNGP09.phx.gbl, Morgan at
ab**@senditon.com wrote on 1/29/04 12:22 PM:
Convert the columns to templates and the columns you don't want to be
editable, change the edit item template control from a textbox to a label.
--Morgan

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BC3EA79F.E60C%sb***@niaid.nih.gov...
Hi,
I have a datagrid databound to a SQL query. I'd like to allow editing of some columns but not all. Is there a way to turn off the conversion of the datagrid cells to textboxes for some columns when the Edit button is
pressed?
Thank you,
Stephan.



Nov 18 '05 #5

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

Similar topics

0
by: Andla Rand | last post by:
Hi, Could you help me to understand how datagrid works. I'm trying to make a datagrid editable. Now most of the tutorials I read says that i...
3
by: Amir | last post by:
Hi every one I had a question I have a DataGrid where I display Employee name and Their Schedule the Grid has 8 Columns ...somewhere in my web...
0
by: DaveR | last post by:
I have a webform with a two-column datagrid based on an Arraylist. The Arraylist draws the data for the two columns from two different tables in an...
8
by: pmud | last post by:
Hi, I have 2 questions: 1. I have an editable data grid with 21 columns. I need to edit only 2 cloumns in this data grid. But when the grid is...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application:...
6
by: Richard L Rosenheim | last post by:
I'm sure it can be done, I haven't been able to find the right article yet. I want to be able to filter the records that the datagrid displays,...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values....
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.