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

Making datagrid partially editable

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


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

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

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

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

Replies have been disabled for this discussion.