Getting a DataGrid to flexibly display a DataView

R

Robert

This is a repost from the other dotnet.csharp forum:

I'm including a simple datagrid control on my web form. I have created
a Dataview (reportListView) onto a data table to populate it. At its
simplest it works - if I define the datasource for the grid to be
'reportListView' and use autogenerate columns then I get all columns
of the view appearing when the page is viewed.
However I now want to restrict the number of columns to be displayed
and also to create a hyperlink column. This should be simple, but when
I try to define the columns (within the properties of the grid), I
don't get any opportunity to select individual fields in the data
source (whereas all of the documentation implies that I will be able
to do so). For instance, no columns are available in the 'Available
Columns' window; I can't see any text fields within the
HyperlinkColumn properties, etc.
It's as if the dataview cannot be expanded correctly when I'm
designing the grid. I'm extremely inexperienced in this area, so any
advice gratefully appreciated.
- Rob.
 
M

Muhammad Arif

You could use, asp:TemplateColumn to have this hyperlink
field. Here is the sample code.

Thanks,
Muhammad Arif
System Analyst, UHC

<asp:datagrid id="ReportGrid" AutoGenerateColumns="False"

Runat="server">

<ItemStyle
HorizontalAlign="Center"></ItemStyle>

<HeaderStyle Font-Size="10pt" Font-
Names="Verdana" Font-Bold="True" HorizontalAlign="Center"


BackColor="#D4DEE3"></HeaderStyle>

<Columns>
<asp:TemplateColumn HeaderText="Download Voice File">

<HeaderTemplate>

Voice
Dictation

</HeaderTemplate>

<ItemTemplate>


<asp:hyperlink runat="server"
Text="Listen/Download" NavigateUrl='<%
# "../../CommonServices/WebPages/DownloadWavFile.aspx?id="
+DataBinder.Eval(Container.DataItem,"VoiceFileName") %>'
Target="_new" ID="Hyperlink3"/>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn
HeaderText="Report Activity Log">

<HeaderTemplate>

Report
Activity Log

</HeaderTemplate>

<ItemTemplate>


<ASP:HYPERLINK id=hlViewActivityLog runat="server"
Target="_new" NavigateUrl='<%# "HViewActivityLog.aspx?id="
+DataBinder.Eval(Container.DataItem,"PkId") %>' Text="View
Log" />

</ItemTemplate>

</asp:TemplateColumn>

</Columns>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top