Making datagrid partially editable

Discussion in 'ASP .Net' started by Stephan Bour, Jan 29, 2004.

  1. Stephan Bour

    Stephan Bour Guest

    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.
     
    Stephan Bour, Jan 29, 2004
    #1
    1. Advertising

  2. Stephan Bour

    Morgan Guest

    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" <> wrote in message
    news:BC3EA79F.E60C%...
    > 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.
    >
     
    Morgan, Jan 29, 2004
    #2
    1. Advertising

  3. Stephan Bour

    Stephan Bour Guest

    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 , Morgan at
    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" <> wrote in message
    > news:BC3EA79F.E60C%...
    >> 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.
    >>

    >
    >
     
    Stephan Bour, Jan 29, 2004
    #3
  4. Stephan Bour

    Morgan Guest

    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" <> wrote in message
    news:BC3EEAD3.E7A9%...
    > 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 , Morgan at
    > 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" <> wrote in message
    > > news:BC3EA79F.E60C%...
    > >> 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.
    > >>

    > >
    > >

    >
     
    Morgan, Jan 30, 2004
    #4
  5. Stephan Bour

    Stephan Bour Guest

    Got it! Thanks a lot.
    Stephan.

    in article , Morgan at
    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" <> wrote in message
    > news:BC3EEAD3.E7A9%...
    >> 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 , Morgan at
    >> 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" <> wrote in message
    >>> news:BC3EA79F.E60C%...
    >>>> 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.
    >>>>
    >>>
    >>>

    >>

    >
    >
     
    Stephan Bour, Jan 30, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cG11ZA==?=

    Making ONLY 2 columns editable in a datagrid

    =?Utf-8?B?cG11ZA==?=, Jan 10, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    3,383
    =?Utf-8?B?Q2hpbm1heQ==?=
    Jan 26, 2005
  2. Making editable datagrid.

    , Oct 13, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    156
  3. UJ
    Replies:
    1
    Views:
    587
    chandan
    Jan 15, 2007
  4. Prasad Peesapati

    Making a cell editable on clicking the cell

    Prasad Peesapati, Feb 3, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    132
    Prasad Peesapati
    Feb 3, 2005
  5. biswaranjan.rath

    making checkbox non-editable

    biswaranjan.rath, Apr 28, 2006, in forum: Javascript
    Replies:
    4
    Views:
    307
    Evertjan.
    Apr 28, 2006
Loading...

Share This Page