advancing with the asp:datagrid

  • Thread starter Thread starter Tim Smith
  • Start date Start date
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!
 
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" />
 
Back
Top