Making datagrid partially editable

  • Thread starter Thread starter Stephan Bour
  • Start date Start date
S

Stephan Bour

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.
 
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
 
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.
 
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
 
Got it! Thanks a lot.
Stephan.

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
 
Back
Top