Professional Web Applications Themes

Bound datatable + unbound column in datagrid - ASP.NET Data Grid Control

Is is possible to create an ASP.NET datagrid that mixes bound data pulled from a database table with an unbound column created by the program? I would like to display several columns from an SQL Server database table (table 1) in an ASP.NET datagrid control. I would also like to display an additional column in the datagrid. The value for the additional column would be generated by plugging values from a couple of columns in the row in table 1 into an SQL SELECT query that selects rows from a different table (table 2), and then performs a calculation that ...

  1. #1

    Default Bound datatable + unbound column in datagrid

    Is is possible to create an ASP.NET datagrid that mixes bound data
    pulled from a database table with an unbound column created by the
    program?

    I would like to display several columns from an SQL Server database
    table (table 1) in an ASP.NET datagrid control. I would also like to
    display an additional column in the datagrid. The value for the
    additional column would be generated by plugging values from a couple
    of columns in the row in table 1 into an SQL SELECT query that selects
    rows from a different table (table 2), and then performs a calculation
    that produces the value for the additional column. (The value for the
    additional column in each row is based on values in other columns in
    that row that came from table 1.) I want the user to be able to use
    the edit, update and delete buttons in the datagrid to process the
    columns that came from table 1, but not table 2.

    Is this possible? Can you add an unbound column to a table that is
    bound to a database table? And if you do so, can you use the edit,
    update, delete buttons in the datagrid to update the datasource (the
    database table) for the columns that came from table 1?

    What would be the best way to go about this? Would it be best to
    generate a dataset from a data adapter, then add a column to the
    datatable in the dataset? I think you have to do this programatically.
    Would you then bind the dataset/datatable to the datagrid?

    Or can you bind a datatable to a datagrid, then add an additional
    column to the datagrid? If you did this, could you do a SELECT on
    table 2 in order to create the value for the additional column?

    Gary Frank Guest

  2. #2

    Default Re: Bound datatable + unbound column in datagrid

    Hi Gary,

    Normally you can use JOIN query get records from multi-tables.



    If the logic to get the additional column is very complicated, you can query
    table1 and have an empty 'reserved' column first, like follows:



    Select column_1, column_2, ., '' As additional_column_name From table1 Where
    Condition



    After fill the query result to a DataTable, you can either



    Loop thru rows in the DataTable to perform calculation for the column, then
    bind the datatable to datagrid



    Or bind the datatable to datagrid, then to perform calculation for the
    column in datagrid_ItemDataBound event.



    HTH







    "Gary Frank" <gary-franksbcglobal.net> wrote in message
    news:1124984098.925059.74710z14g2000cwz.googlegro ups.com...
    > Is is possible to create an ASP.NET datagrid that mixes bound data
    > pulled from a database table with an unbound column created by the
    > program?
    >
    > I would like to display several columns from an SQL Server database
    > table (table 1) in an ASP.NET datagrid control. I would also like to
    > display an additional column in the datagrid. The value for the
    > additional column would be generated by plugging values from a couple
    > of columns in the row in table 1 into an SQL SELECT query that selects
    > rows from a different table (table 2), and then performs a calculation
    > that produces the value for the additional column. (The value for the
    > additional column in each row is based on values in other columns in
    > that row that came from table 1.) I want the user to be able to use
    > the edit, update and delete buttons in the datagrid to process the
    > columns that came from table 1, but not table 2.
    >
    > Is this possible? Can you add an unbound column to a table that is
    > bound to a database table? And if you do so, can you use the edit,
    > update, delete buttons in the datagrid to update the datasource (the
    > database table) for the columns that came from table 1?
    >
    > What would be the best way to go about this? Would it be best to
    > generate a dataset from a data adapter, then add a column to the
    > datatable in the dataset? I think you have to do this programatically.
    > Would you then bind the dataset/datatable to the datagrid?
    >
    > Or can you bind a datatable to a datagrid, then add an additional
    > column to the datagrid? If you did this, could you do a SELECT on
    > table 2 in order to create the value for the additional column?
    >

    Elton Wang Guest

  3. #3

    Default Re: Bound datatable + unbound column in datagrid

    Elton,

    Thank you Elton! I didn't realize you could do an SQL query that
    returns an empty column. It looks like a very clean solution. I'm
    wondering how this will work if I add the edit, update and delete
    buttons to the Datagrid. Will the empty column cause an error when
    these datagrid buttons attempt to update the datasource table?

    Gary Frank

    --
    Sent via .NET Newsgroups
    [url]http://www.dotnetnewsgroups.com[/url]
    Gary Frank Guest

  4. #4

    Default Re: Bound datatable + unbound column in datagrid

    Hi Gary,

    I don't think there are any troubles in Update/Delete logic, (Edit only
    works on web controls, no direct connection with DB). You can easily control
    to select data from proper columns for updating/deleting data in DB.



    HTH





    "Gary Frank" <gary-franksbcglobal.net> wrote in message
    news:e%23feJVaqFHA.1328tk2msftngp13.phx.gbl...
    > Elton,
    >
    > Thank you Elton! I didn't realize you could do an SQL query that
    > returns an empty column. It looks like a very clean solution. I'm
    > wondering how this will work if I add the edit, update and delete
    > buttons to the Datagrid. Will the empty column cause an error when
    > these datagrid buttons attempt to update the datasource table?
    >
    > Gary Frank
    >
    > --
    > Sent via .NET Newsgroups
    > [url]http://www.dotnetnewsgroups.com[/url]

    Elton Wang Guest

Similar Threads

  1. Replies: 0
    Last Post: March 25th, 05:39 AM
  2. Move bound column to right of dynamic column in datagrid?
    By John E. in forum ASP.NET Data Grid Control
    Replies: 3
    Last Post: March 28th, 01:29 PM
  3. Binding Two DataTable Columns to One DataGrid Column
    By quiggle in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: April 2nd, 04:12 PM
  4. Bound Column or Template Column (w dAdapater?) in DataGrid
    By Ravichandran Mahalingam in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: January 9th, 03:30 PM
  5. Trying to hide a datatable column from my datagrid... please help
    By jonnylbluejeans in forum ASP.NET General
    Replies: 4
    Last Post: July 24th, 09:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139