473,394 Members | 1,718 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,394 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 1774
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 should turn the Enable ViewState off. Why is that? ...
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 Application the admin should have an option of...
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 SQL database. The data is displayed in datagrid...
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 displayed in Edit mode, all the columns show long...
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 program customizes itself for sorting,...
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: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
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, but still have an editable datagrid. That is, I...
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. To make the thing complicated, one of the...
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 EditCommandColumn in the DataGrid. This is the...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.