dynamically adding columns to datagrid from sql statement
-
hi, i have seen some of the datagrid samples in internet. In most of the cases the datagrid is bind to some table. But if i want to display the output of an sql query(contains select statement with n number of columns) in Datagrid, i can simply use AutogenerateColumns=true and populate the datagrid without having any bound columns. That is fine. If i want to add some more extra columns like a checkbox column and an edit link button column i can do it using property builder. But,the problem is how can i order the columns in datagrid. for example: 1st col: checkboxes 2nd-4th col : from sql statemnt 5th col : edit link button Also how can i make a random column from sql statement to a hyperlink column. thanks
-
hi, i have seen some of the datagrid samples in internet. In most of the cases the datagrid is bind to some table. But if i want to display the output of an sql query(contains select statement with n number of columns) in Datagrid, i can simply use AutogenerateColumns=true and populate the datagrid without having any bound columns. That is fine. If i want to add some more extra columns like a checkbox column and an edit link button column i can do it using property builder. But,the problem is how can i order the columns in datagrid. for example: 1st col: checkboxes 2nd-4th col : from sql statemnt 5th col : edit link button Also how can i make a random column from sql statement to a hyperlink column. thanks
One simplest way is, add few temprory columns in the query, wherever you want add column in the grid. Then bind that query result to the datagrid. Example: ======== Actual query is, select column1, column2, column3 from table1 Imagine you want to add columns in between 1 and 2, 2 and 3 then the query should be, select column1, '' as tempcol1, column2, '' as tempcol2, column3 from table1 then on the itemdatabound event you can add any control like (button, linkbutton, or dropdownlist) on the column. Ram
-
One simplest way is, add few temprory columns in the query, wherever you want add column in the grid. Then bind that query result to the datagrid. Example: ======== Actual query is, select column1, column2, column3 from table1 Imagine you want to add columns in between 1 and 2, 2 and 3 then the query should be, select column1, '' as tempcol1, column2, '' as tempcol2, column3 from table1 then on the itemdatabound event you can add any control like (button, linkbutton, or dropdownlist) on the column. Ram
-
Example: ======== Actual query is, select column1, column2, column3 from table1 Imagine you want to add columns in between 1 and 2, 2 and 3 then the query should be, select column1, '' as tempcol1, column2, '' as tempcol2, column3 from table1 then on the itemdatabound event you can add any control like (button, linkbutton, or dropdownlist) on the column Explanation: ============ You just execute the these two queries. First query will return three columns, second query will return five columns. The temp columns are not available in any table, which will be used to create a column in the grid. You just execute this queries in the query analyzer and check. Ram