advancing with the asp:datagrid

T

Tim Smith

In my .cs code I populate set the DataSource appropriately and I can
get my DataGrid to appear, though sorting throws an error
'dgDataGrid1__ctl1__ctl0' of type 'DataGridLinkButton' must be placed
inside a form tag

But ignoring that, with my asp:DataGrid how can I have a column of
values each with a link e.g.

<a href="Details.aspx?id=" + MY_NBR>MY_NBR</a>


<asp:DataGrid id="ReportHeader" runat="server" AllowSorting="True"
AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField="MY_GROUP"
HeaderText="Report Group" SortExpression="MY_GROUP">
</asp:BoundColumn>
<asp:BoundColumn DataField="MY_NAME"
HeaderText="Report Name" SortExpression="MY_NAME">
</asp:BoundColumn>
<asp:BoundColumn DataField="MY_NBR"
HeaderText="Report Nbr" DataFormatString="{0:d}"
SortExpression="MY_NBR">
</asp:BoundColumn>
</Columns>
</asp:DataGrid>

thanks!
 
C

Chris Jackson

That's what the HyperLinkColumn is for. You set the field that you pull for
the URL (in this case, MY_NBR), then set the format string, and then the {0}
portion will substitute in the field from the database. The DataTextField
property then shows what to display, and if you want to decorate this
somehow just use the DataTextFormatString property.

eg:

<asp:HyperLinkColumn HeaderText="Report Nbr" DataNavigateUrlField="MY_NBR"
DataNavigateUrlFormatString="details.aspx?id={0}" DataTextField="MY_NBR" />
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top