IDs in a DataGrid

Discussion in 'ASP .Net Web Controls' started by MikeD, Nov 27, 2003.

  1. MikeD

    MikeD Guest

    Hello,

    I'm still a bit new to all this and am probably asking the question the
    wrong way but...

    I would like to represent a SQL Table in a data grid and allow the user to
    edit the values. In my simplest scenario a table has only an ID field and a
    Name field. What I would like to be able to do is (if possible) only show
    the Name field in the datagrid, but when I do I run into problems about
    identifying that record when I wish to save the result back to the table.

    So far the only way I have managed to do it is to also show the ID field and
    have it editable, but this could cause problems as the ID is auto generated
    by the table and can not change.

    If I make the ID column read only then it errors when I try to read the
    value in the Submit code.

    How should I do this so the ID is preferably not visible but at a minimum is
    not editable?

    TIA

    <M>ike
    MikeD, Nov 27, 2003
    #1
    1. Advertising

  2. MikeD

    Sink Guest

    Set the column's Visble=False

    <asp:BoundColumn Visbile="False" DataField="<Your Key
    Field>"></asp:BoundColumn>

    Regards
    Sink
    >-----Original Message-----
    >Hello,
    >
    >I'm still a bit new to all this and am probably asking

    the question the
    >wrong way but...
    >
    >I would like to represent a SQL Table in a data grid and

    allow the user to
    >edit the values. In my simplest scenario a table has only

    an ID field and a
    >Name field. What I would like to be able to do is (if

    possible) only show
    >the Name field in the datagrid, but when I do I run into

    problems about
    >identifying that record when I wish to save the result

    back to the table.
    >
    >So far the only way I have managed to do it is to also

    show the ID field and
    >have it editable, but this could cause problems as the ID

    is auto generated
    >by the table and can not change.
    >
    >If I make the ID column read only then it errors when I

    try to read the
    >value in the Submit code.
    >
    >How should I do this so the ID is preferably not visible

    but at a minimum is
    >not editable?
    >
    >TIA
    >
    ><M>ike
    >
    >
    >.
    >
    Sink, Nov 28, 2003
    #2
    1. Advertising

  3. MikeD

    Guest Guest

    corrected spelling
    >-----Original Message-----
    >Set the column's Visible=False
    >
    ><asp:BoundColumn Visible="False" DataField="<Your Key
    >Field>"></asp:BoundColumn>
    >
    >Regards
    >Sink
    >>-----Original Message-----
    >>Hello,
    >>
    >>I'm still a bit new to all this and am probably asking

    >the question the
    >>wrong way but...
    >>
    >>I would like to represent a SQL Table in a data grid and

    >allow the user to
    >>edit the values. In my simplest scenario a table has

    only
    >an ID field and a
    >>Name field. What I would like to be able to do is (if

    >possible) only show
    >>the Name field in the datagrid, but when I do I run into

    >problems about
    >>identifying that record when I wish to save the result

    >back to the table.
    >>
    >>So far the only way I have managed to do it is to also

    >show the ID field and
    >>have it editable, but this could cause problems as the

    ID
    >is auto generated
    >>by the table and can not change.
    >>
    >>If I make the ID column read only then it errors when I

    >try to read the
    >>value in the Submit code.
    >>
    >>How should I do this so the ID is preferably not visible

    >but at a minimum is
    >>not editable?
    >>
    >>TIA
    >>
    >><M>ike
    >>
    >>
    >>.
    >>

    >.
    >
    Guest, Nov 28, 2003
    #3
  4. MikeD

    James Radke Guest

    Mike,

    It depends on how you are planning to do the update. Are you planning on
    having a textbox entry by using the edit command within a datagrid row, or
    are you planning on simply displaying a textbox, and allowing the user to
    key the data right in, like an excel spreadsheet?

    Jim

    "MikeD" <mikedotdinnis@abraxashyphenukdotcom> wrote in message
    news:%...
    > Hello,
    >
    > I'm still a bit new to all this and am probably asking the question the
    > wrong way but...
    >
    > I would like to represent a SQL Table in a data grid and allow the user to
    > edit the values. In my simplest scenario a table has only an ID field and

    a
    > Name field. What I would like to be able to do is (if possible) only show
    > the Name field in the datagrid, but when I do I run into problems about
    > identifying that record when I wish to save the result back to the table.
    >
    > So far the only way I have managed to do it is to also show the ID field

    and
    > have it editable, but this could cause problems as the ID is auto

    generated
    > by the table and can not change.
    >
    > If I make the ID column read only then it errors when I try to read the
    > value in the Submit code.
    >
    > How should I do this so the ID is preferably not visible but at a minimum

    is
    > not editable?
    >
    > TIA
    >
    > <M>ike
    >
    >
    James Radke, Nov 28, 2003
    #4
  5. MikeD

    MikeD Guest

    Hello Jim,

    I was planning to use the edit command within the datagrid row as the data
    entry method, but was having difficulty in returning the ID. I've since
    discovered that I should have set the DataKey value and can then call that
    in the update code, plus it makes the field un-editable which was exactly
    what I was after.

    Thank you for taking the trouble to reply.

    Regards,

    <M>ike

    "James Radke" <> wrote in message
    news:%...
    > Mike,
    >
    > It depends on how you are planning to do the update. Are you planning on
    > having a textbox entry by using the edit command within a datagrid row, or
    > are you planning on simply displaying a textbox, and allowing the user to
    > key the data right in, like an excel spreadsheet?
    >
    > Jim
    >
    > "MikeD" <mikedotdinnis@abraxashyphenukdotcom> wrote in message
    > news:%...
    > > Hello,
    > >
    > > I'm still a bit new to all this and am probably asking the question the
    > > wrong way but...
    > >
    > > I would like to represent a SQL Table in a data grid and allow the user

    to
    > > edit the values. In my simplest scenario a table has only an ID field

    and
    > a
    > > Name field. What I would like to be able to do is (if possible) only

    show
    > > the Name field in the datagrid, but when I do I run into problems about
    > > identifying that record when I wish to save the result back to the

    table.
    > >
    > > So far the only way I have managed to do it is to also show the ID field

    > and
    > > have it editable, but this could cause problems as the ID is auto

    > generated
    > > by the table and can not change.
    > >
    > > If I make the ID column read only then it errors when I try to read the
    > > value in the Submit code.
    > >
    > > How should I do this so the ID is preferably not visible but at a

    minimum
    > is
    > > not editable?
    > >
    > > TIA
    > >
    > > <M>ike
    > >
    > >

    >
    >
    MikeD, Dec 1, 2003
    #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. Jim Bancroft

    DataGrid appending to my ItemTemplate IDs?

    Jim Bancroft, Dec 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    315
    Jim Bancroft
    Dec 28, 2004
  2. JV
    Replies:
    1
    Views:
    369
  3. Replies:
    6
    Views:
    846
  4. Replies:
    2
    Views:
    701
    Beat Bolli
    Jun 21, 2005
  5. problem with adding IDs to webcontrols in datagrid

    , Sep 16, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    97
Loading...

Share This Page