heremy,
if you know what fields your query will return, you can just use the Column
Editor and add the fields into there manually. This pre-builds the grid
columns for you. You can even convert these fields into template fields. You
will need to read up on <' % Eval("ColumnName") %'> and <'% Bind("ColunName"
%'> so that the grid knows what to bind into each column from your
datasource.
Question for you: why not use stored proceedures and use the DataSet
designer to do all of the heavy lifting for you? you can ass multiple table
adapters for your entire project and in the tableadapters u have built in
support for C.R.U.D. queries. Once u add the table adapter, u can bind to
that via a objectdatasource and volah the columns appear in your grid at
designtime and you also get sorting and paging for free plus Editing,
Deleting and Inserting.
[quoted text, click to view] "Phil H" wrote:
> On 14 Dec, 15:43, "JamesB" <jam...@somewhere.com.net.com.net> wrote:
> > OK, so I now have a gridview on my page. Because my data isn't stored in
> > such a way that I can bind the grid directly to the database, I am creating
> > a DataTable in code, running some procedures to fill this with data in the
> > right format from the database, all processed accordingly, then binding the
> > DataTable to the grid.
> > This works, but newline characters (i.e. "\n") don't work. I also tried
> > putting them in as <br> but no joy.
> >
> > Doing some googling, I have read that I need to use "TemplateFields" on the
> > grid. If I go to the Column Editor for my grid, I don't have any columns to
> > edit (they are generated at runtime by the binding to my datatable I guess)
> > so I can't convert them to template ones.
> >
> > Any thoughts? I tried adding some columns and setting the
> > AutoGenerateColumns to false, but then my data doesn't appear so I must be
> > missing some other step...!
>
> Hi Jeremy
>
> In the circumstances you describe the best alternative is to use an
> ObjectDataSource linked to a class file (placed in the App_Code
> folder) containing your data construction code in the form of a public
> function that returns the resulting DataTable, and then set the
> ObjectDataSource as the DataSourceID property for the GridView
> control. The designer wizard for setting up templated databound
> controls will not automatically list the column names, but if template
> columns are added manually, and the source column names typed in
> correctly, it will work Ok at run time. Also, if automatic column
> generation is set to true, that should work Ok at run time as well.
> There are many other steps to setting this up fully which are too
> numerous to describe here, but if you search the help files you should
> find what you need.
>
> HTH
> Phil