Datareader, Datagrid and hyperlinks

Discussion in 'ASP .Net Web Controls' started by Grant, Dec 17, 2004.

  1. Grant

    Grant Guest

    I am filling a datareader and then assigning the reader to the datagrid as
    follows:

    SqlDataReader reader = ADOConnect.populateDatareader();
    AllResultsDataGrid.DataSource = reader;
    AllResultsDataGrid.HeaderStyle.Font.Bold = true;
    AllResultsDataGrid.DataBind();

    My question is how do I specify that foreach row in the first column - the
    text is a hyperlink? This column contains an ID which Id like to have as a
    hyperlink so that the user can be directed to another page where they can
    edit information for that record. I can do this when binding the datagrid to
    a recordset, but Id like to use the datareader instead if possible.

    Another question I have with this datagrid is, I want to be able to delete a
    row from this page, so could I add an additional column at runtime with a
    button or link foreach record - with a funtion attached?

    Cheers,
    Grant
     
    Grant, Dec 17, 2004
    #1
    1. Advertising

  2. If you have created the datagrid through tags in the designer (assuming VS
    is your editor), you can right click on it, choose the "property builder"
    option and add a hyperLinkColumn to the grid and move it to the first
    position in the list of columns to make it the first column.
    Hope this helps
    -Andrew

    "Grant" <> wrote in message
    news:%...
    >I am filling a datareader and then assigning the reader to the datagrid as
    >follows:
    >
    > SqlDataReader reader = ADOConnect.populateDatareader();
    > AllResultsDataGrid.DataSource = reader;
    > AllResultsDataGrid.HeaderStyle.Font.Bold = true;
    > AllResultsDataGrid.DataBind();
    >
    > My question is how do I specify that foreach row in the first column - the
    > text is a hyperlink? This column contains an ID which Id like to have as a
    > hyperlink so that the user can be directed to another page where they can
    > edit information for that record. I can do this when binding the datagrid
    > to a recordset, but Id like to use the datareader instead if possible.
    >
    > Another question I have with this datagrid is, I want to be able to delete
    > a row from this page, so could I add an additional column at runtime with
    > a button or link foreach record - with a funtion attached?
    >
    > Cheers,
    > Grant
    >
     
    Andrew L. Van Slaars, Dec 17, 2004
    #2
    1. Advertising

  3. I just saw your second question... you could do this using the same steps as
    listed in my last response, but instead of the hyperlink column, use the
    button column, or you could use a template column if you wanted more control
    and options within the cells.

    -Andrew

    "Grant" <> wrote in message
    news:%...
    >I am filling a datareader and then assigning the reader to the datagrid as
    >follows:
    >
    > SqlDataReader reader = ADOConnect.populateDatareader();
    > AllResultsDataGrid.DataSource = reader;
    > AllResultsDataGrid.HeaderStyle.Font.Bold = true;
    > AllResultsDataGrid.DataBind();
    >
    > My question is how do I specify that foreach row in the first column - the
    > text is a hyperlink? This column contains an ID which Id like to have as a
    > hyperlink so that the user can be directed to another page where they can
    > edit information for that record. I can do this when binding the datagrid
    > to a recordset, but Id like to use the datareader instead if possible.
    >
    > Another question I have with this datagrid is, I want to be able to delete
    > a row from this page, so could I add an additional column at runtime with
    > a button or link foreach record - with a funtion attached?
    >
    > Cheers,
    > Grant
    >
     
    Andrew L. Van Slaars, Dec 17, 2004
    #3
  4. Grant

    Grant Guest

    Thanks for replying Andrew that did the trick. One more question though, I
    have set one of the columns to be a delete colum as in the following code:

    ButtonColumn hlcDelete = new ButtonColumn();
    hlcDelete.Text = "Delete";

    Problem is when the button is created it has no ID or event handler assigned
    to it. i need to be able to determine either what row was selected or what
    the value of the ID field in that row is so that I can create a SQL query to
    delete that record. There are not any samples that i can find - all of them
    are done in ASP code, and I prefer not to use the designer to set these
    sorts of things. Can this sort of thing be done in c# code when Im binding
    the datareader?

    Cheers,
    Grant


    "Andrew L. Van Slaars" <> wrote in message
    news:...
    >I just saw your second question... you could do this using the same steps
    >as listed in my last response, but instead of the hyperlink column, use the
    >button column, or you could use a template column if you wanted more
    >control and options within the cells.
    >
    > -Andrew
    >
    > "Grant" <> wrote in message
    > news:%...
    >>I am filling a datareader and then assigning the reader to the datagrid as
    >>follows:
    >>
    >> SqlDataReader reader = ADOConnect.populateDatareader();
    >> AllResultsDataGrid.DataSource = reader;
    >> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
    >> AllResultsDataGrid.DataBind();
    >>
    >> My question is how do I specify that foreach row in the first column -
    >> the text is a hyperlink? This column contains an ID which Id like to have
    >> as a hyperlink so that the user can be directed to another page where
    >> they can edit information for that record. I can do this when binding the
    >> datagrid to a recordset, but Id like to use the datareader instead if
    >> possible.
    >>
    >> Another question I have with this datagrid is, I want to be able to
    >> delete a row from this page, so could I add an additional column at
    >> runtime with a button or link foreach record - with a funtion attached?
    >>
    >> Cheers,
    >> Grant
    >>

    >
    >
     
    Grant, Dec 17, 2004
    #4
  5. Grant

    Grant Guest

    No worries I figured it out. I just set the text using the property builder
    then assigned an event handler to it. Then get the cell value using

    TableCell itemCell = e.Item.Cells[2];
    string item = itemCell.Text;

    Couldnt be easier.

    Cheers,
    Grant

    "Grant" <> wrote in message
    news:O%23bWd%...
    > Thanks for replying Andrew that did the trick. One more question though, I
    > have set one of the columns to be a delete colum as in the following code:
    >
    > ButtonColumn hlcDelete = new ButtonColumn();
    > hlcDelete.Text = "Delete";
    >
    > Problem is when the button is created it has no ID or event handler
    > assigned to it. i need to be able to determine either what row was
    > selected or what the value of the ID field in that row is so that I can
    > create a SQL query to delete that record. There are not any samples that i
    > can find - all of them are done in ASP code, and I prefer not to use the
    > designer to set these sorts of things. Can this sort of thing be done in
    > c# code when Im binding the datareader?
    >
    > Cheers,
    > Grant
    >
    >
    > "Andrew L. Van Slaars" <> wrote in message
    > news:...
    >>I just saw your second question... you could do this using the same steps
    >>as listed in my last response, but instead of the hyperlink column, use
    >>the button column, or you could use a template column if you wanted more
    >>control and options within the cells.
    >>
    >> -Andrew
    >>
    >> "Grant" <> wrote in message
    >> news:%...
    >>>I am filling a datareader and then assigning the reader to the datagrid
    >>>as follows:
    >>>
    >>> SqlDataReader reader = ADOConnect.populateDatareader();
    >>> AllResultsDataGrid.DataSource = reader;
    >>> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
    >>> AllResultsDataGrid.DataBind();
    >>>
    >>> My question is how do I specify that foreach row in the first column -
    >>> the text is a hyperlink? This column contains an ID which Id like to
    >>> have as a hyperlink so that the user can be directed to another page
    >>> where they can edit information for that record. I can do this when
    >>> binding the datagrid to a recordset, but Id like to use the datareader
    >>> instead if possible.
    >>>
    >>> Another question I have with this datagrid is, I want to be able to
    >>> delete a row from this page, so could I add an additional column at
    >>> runtime with a button or link foreach record - with a funtion attached?
    >>>
    >>> Cheers,
    >>> Grant
    >>>

    >>
    >>

    >
    >
     
    Grant, Dec 18, 2004
    #5
  6. You could also check out the ASP.NET quick start pages at

    http://samples.gotdotnet.com/quickstart/aspplus/

    The "Server-side data access" pages go through the datagrid at a high level.

    --
    Ben Strackany
    www.developmentnow.com


    "Grant" <> wrote in message
    news:...
    > No worries I figured it out. I just set the text using the property

    builder
    > then assigned an event handler to it. Then get the cell value using
    >
    > TableCell itemCell = e.Item.Cells[2];
    > string item = itemCell.Text;
    >
    > Couldnt be easier.
    >
    > Cheers,
    > Grant
    >
    > "Grant" <> wrote in message
    > news:O%23bWd%...
    > > Thanks for replying Andrew that did the trick. One more question though,

    I
    > > have set one of the columns to be a delete colum as in the following

    code:
    > >
    > > ButtonColumn hlcDelete = new ButtonColumn();
    > > hlcDelete.Text = "Delete";
    > >
    > > Problem is when the button is created it has no ID or event handler
    > > assigned to it. i need to be able to determine either what row was
    > > selected or what the value of the ID field in that row is so that I can
    > > create a SQL query to delete that record. There are not any samples that

    i
    > > can find - all of them are done in ASP code, and I prefer not to use the
    > > designer to set these sorts of things. Can this sort of thing be done in
    > > c# code when Im binding the datareader?
    > >
    > > Cheers,
    > > Grant
    > >
    > >
    > > "Andrew L. Van Slaars" <> wrote in message
    > > news:...
    > >>I just saw your second question... you could do this using the same

    steps
    > >>as listed in my last response, but instead of the hyperlink column, use
    > >>the button column, or you could use a template column if you wanted more
    > >>control and options within the cells.
    > >>
    > >> -Andrew
    > >>
    > >> "Grant" <> wrote in message
    > >> news:%...
    > >>>I am filling a datareader and then assigning the reader to the datagrid
    > >>>as follows:
    > >>>
    > >>> SqlDataReader reader = ADOConnect.populateDatareader();
    > >>> AllResultsDataGrid.DataSource = reader;
    > >>> AllResultsDataGrid.HeaderStyle.Font.Bold = true;
    > >>> AllResultsDataGrid.DataBind();
    > >>>
    > >>> My question is how do I specify that foreach row in the first column -
    > >>> the text is a hyperlink? This column contains an ID which Id like to
    > >>> have as a hyperlink so that the user can be directed to another page
    > >>> where they can edit information for that record. I can do this when
    > >>> binding the datagrid to a recordset, but Id like to use the datareader
    > >>> instead if possible.
    > >>>
    > >>> Another question I have with this datagrid is, I want to be able to
    > >>> delete a row from this page, so could I add an additional column at
    > >>> runtime with a button or link foreach record - with a funtion

    attached?
    > >>>
    > >>> Cheers,
    > >>> Grant
    > >>>
    > >>
    > >>

    > >
    > >

    >
    >
     
    Ben Strackany, Dec 22, 2004
    #6
    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. Bart Schelkens

    Datagrid and datareader

    Bart Schelkens, Jul 27, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    3,678
    Bart Schelkens
    Jul 28, 2004
  2. Grant

    Datareader, Datagrid and hyperlinks

    Grant, Dec 17, 2004, in forum: ASP .Net Building Controls
    Replies:
    5
    Views:
    151
    Ben Strackany
    Dec 22, 2004
  3. Max

    DataGrid Paging and DataReader

    Max, Sep 30, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    116
  4. Richard Jonker

    dynamically add hyperlinks and buttons to a datagrid

    Richard Jonker, Oct 2, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    729
    Niraj Ranka
    Oct 3, 2006
  5. Steve Randall

    Datagrid and Hyperlinks,,,

    Steve Randall, Jan 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    106
    Jos Branders
    Jan 7, 2004
Loading...

Share This Page