Populate label from Datagrid selection

Discussion in 'ASP .Net Datagrid Control' started by Euan, Apr 15, 2005.

  1. Euan

    Euan Guest

    Hi there,

    This might be a simple enough question for most of you. But I am pulling
    my hair out with this.

    I have a datagrid populated from a database. Its a booking form. You
    push a button column to select the row. And now I need to give some
    specific details from that row in to a label.
    Lets say Course Name, Course Date, Trainer, and Location.

    I have NO idea how to get those specific details populated in to a
    label. How do I select those specific parts from the data reader? I know
    the record. And I know I have the info. But I just want the specific parts!

    Thanks for your help,
    Euan
     
    Euan, Apr 15, 2005
    #1
    1. Advertising

  2. Euan

    Elton Wang Guest

    Hi

    You can use following steps to do your work.
    1) Get all data, including data to be shown in datagrid
    (e.g. recordID, description, and others) and detailed data
    (e.g. Course Name, Course Date, Trainer, and Location) to
    fill into a datatable.

    2) Build a datagrid with DataKeyField = "recordID" and few
    BoundColumns (for recorded, description, and so on) and a
    ButtonColumn.

    3) Bind the datagrid with the datatable, and in the mean
    time save the datatable in Session.

    4) Build ItemCommand event. In the event retrieve clicked
    recordID and then pull detailed data from datatable in
    Session by following code:

    string recordID = datagrid.DataKeys
    [e.Item.ItemIndex].ToString();
    DataTable data = (DataTable)Session["source"];
    DataView dv = data.DefaultView;
    dv.RowFilter = "recordID='" + recordID + "'";
    DataRowView drv = dv[0];
    string CourseName = drv["CourseName"];
    string CourseDate = drv["CourseDate"];
    string Trainer = drv["Trainer"];
    string Location = drv["Location"];

    HTH

    Elton Wang



    >-----Original Message-----
    >Hi there,
    >
    >This might be a simple enough question for most of you.

    But I am pulling
    >my hair out with this.
    >
    >I have a datagrid populated from a database. Its a

    booking form. You
    >push a button column to select the row. And now I need to

    give some
    >specific details from that row in to a label.
    >Lets say Course Name, Course Date, Trainer, and Location.
    >
    >I have NO idea how to get those specific details

    populated in to a
    >label. How do I select those specific parts from the data

    reader? I know
    >the record. And I know I have the info. But I just want

    the specific parts!
    >
    >Thanks for your help,
    >Euan
    >.
    >
     
    Elton Wang, Apr 16, 2005
    #2
    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. Mark
    Replies:
    2
    Views:
    906
  2. Chris Kettenbach

    Listbox selection to populate another listbox?

    Chris Kettenbach, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,660
    Chris Kettenbach
    Jun 16, 2005
  3. Satish
    Replies:
    8
    Views:
    9,698
    Satish
    Mar 31, 2008
  4. Enjoy Life
    Replies:
    2
    Views:
    291
    Roland Hall
    Feb 23, 2005
  5. Knut Krueger
    Replies:
    8
    Views:
    293
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page