473,748 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1797
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.ni h.gov> wrote in message
news:BC3EA79F.E 60C%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
EditCommandColu mn to generate all columns contained in my databinder and
making them editable. In the example below, the "Descriptio n" 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 EditCommandColu mn?
<asp:DataGrid id="ByJob" AutoGenerateCol umns="true"
OnEditCommand=" ByJob_Edit" OnCancelCommand ="ByJob_Canc el"
OnUpdateCommand ="ByJob_Upda te" runat="server">
<HeaderStyle backcolor="Blac k" forecolor="Whit e" font-bold="True"
horizontalalign ="Left" />
<Columns>
<asp:EditComman dColumn EditText="Edit"
CancelText="Can cel"
UpdateText="Upd ate"
ItemStyle-Wrap="false"
/>

<asp:TemplateCo lumn>

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

<ItemTemplate >
<asp:Label
Text='<%# DataBinder.Eval (Container.Data Item,
"Descriptio n") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

Thanks,
Stephan.

in article ut************* *@TK2MSFTNGP09. phx.gbl, Morgan at
ab**@senditon.c om 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.ni h.gov> wrote in message
news:BC3EA79F.E 60C%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 EditItemTemplat e.
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:TemplateCo lumn>
<ItemTemplate >
<asp:Label id="LabelReadOn lyDisplayMode"
runat="server"> </asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:Label id="LabelReadOn lyEditMode"
runat="server"> </asp:Label>
</EditItemTemplat e>
</asp:TemplateCol umn>
</Columns>

Morgan

"Stephan Bour" <sb***@niaid.ni h.gov> wrote in message
news:BC3EEAD3.E 7A9%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
EditCommandColu mn to generate all columns contained in my databinder and
making them editable. In the example below, the "Descriptio n" 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 EditCommandColu mn?
<asp:DataGrid id="ByJob" AutoGenerateCol umns="true"
OnEditCommand=" ByJob_Edit" OnCancelCommand ="ByJob_Canc el"
OnUpdateCommand ="ByJob_Upda te" runat="server">
<HeaderStyle backcolor="Blac k" forecolor="Whit e" font-bold="True"
horizontalalign ="Left" />
<Columns>
<asp:EditComman dColumn EditText="Edit"
CancelText="Can cel"
UpdateText="Upd ate"
ItemStyle-Wrap="false"
/>

<asp:TemplateCo lumn>

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

<ItemTemplate >
<asp:Label
Text='<%# DataBinder.Eval (Container.Data Item,
"Descriptio n") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

Thanks,
Stephan.

in article ut************* *@TK2MSFTNGP09. phx.gbl, Morgan at
ab**@senditon.c om 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.ni h.gov> wrote in message
news:BC3EA79F.E 60C%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.c om 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 EditItemTemplat e.
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:TemplateCo lumn>
<ItemTemplate >
<asp:Label id="LabelReadOn lyDisplayMode"
runat="server"> </asp:Label>
</ItemTemplate>
<EditItemTempla te>
<asp:Label id="LabelReadOn lyEditMode"
runat="server"> </asp:Label>
</EditItemTemplat e>
</asp:TemplateCol umn>
</Columns>

Morgan

"Stephan Bour" <sb***@niaid.ni h.gov> wrote in message
news:BC3EEAD3.E 7A9%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
EditCommandColu mn to generate all columns contained in my databinder and
making them editable. In the example below, the "Descriptio n" 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 EditCommandColu mn?
<asp:DataGrid id="ByJob" AutoGenerateCol umns="true"
OnEditCommand=" ByJob_Edit" OnCancelCommand ="ByJob_Canc el"
OnUpdateCommand ="ByJob_Upda te" runat="server">
<HeaderStyle backcolor="Blac k" forecolor="Whit e" font-bold="True"
horizontalalign ="Left" />
<Columns>
<asp:EditComman dColumn EditText="Edit"
CancelText="Can cel"
UpdateText="Upd ate"
ItemStyle-Wrap="false"
/>

<asp:TemplateCo lumn>

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

<ItemTemplate >
<asp:Label
Text='<%# DataBinder.Eval (Container.Data Item,
"Descriptio n") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>

Thanks,
Stephan.

in article ut************* *@TK2MSFTNGP09. phx.gbl, Morgan at
ab**@senditon.c om 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.ni h.gov> wrote in message
news:BC3EA79F.E 60C%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
1181
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? If i turn this off then i need to support building the datagrid because the datagrid is not persistant. Right?
3
1645
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 "quick" changing the schedule for current week now I know how to make DataGrid Editable but when I make it editable using "Edit" button ..every cell in the row where "edit" button is goes into editable mode now my question is
0
1348
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 as expected but when user clicks the Edit link, the cells do NOT turn into editable text boxes. I actually need only the first column to be editable but any ideas on getting the whole row editable would help at first. Apologies for the amount of...
8
2406
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 text boxes whichmakes the user to SCROLL a lot. I need only these 2 cloumns to be displayed in Edit mode. Is that possible & how? 2. Also, even when the data grid is not displayed in the edit mode, it
1
2692
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, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I am missing something basic here... Need help... Thanks much
1
4235
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 the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
6
1613
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 only want records from the table where "State= 'CA'" are to be displayed, but where the user can still edit/add/delete records. The only examples I have found utilizes DataViews, which apparently are not editable. Can someone point me to the...
7
3228
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 column need to be a date picker field. I know things will be easier with ASPX datagrid.
9
2726
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.