Re: Next problem :) GridView - formatting text



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.



"Phil H" wrote:

On 14 Dec, 15:43, "JamesB" <jam...@xxxxxxxxxxxxxxxxxxxxxxxxx> 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

.



Relevant Pages

  • Re: VB.NET Datagrid with pictures
    ... Right click on your grid and choose "Property Builder" ... Right click on your grid and choose "Edit Template" and when the sub ... delete the label control and replace it with an Image control. ... I have a datagrid on my form that I populate via code like this... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Aligning thumbnail images
    ... Tony Cooper - Orlando, Florida ... View your grid or your guidelines, ... Save that file as "Template". ... Now bring in your images in a layer or layers above the template ...
    (alt.graphics.photoshop)
  • Re: Can anyone suggest a flowchart program
    ... Create a "template" shape for each type of shape you'll need. ... I also use it copy lines, then just drag the ... you can create the grid layout (i.e. ...
    (comp.lang.php)
  • Re: How do I print guide lines on calendars in Publisher 2003
    ... That's a grid, as in a table. ... JoAnn Paules ... > a 'box' as it appears on the template. ... >> Checked by AVG anti-virus system. ...
    (microsoft.public.publisher)
  • Re: tcl/tk visual gipsy --beginner questions
    ... > visual gipsy were introduced... ... > the geometry rules behind pack and grid? ... > an editor yet for tcl/tk. ... i dont think i'd want to work in tk without drag and drop!! ...
    (comp.lang.tcl)