DataGrid Link Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone please tell me how I turn an ItemTemplate into a link? I don't
what to use a HyperlinkColumn as I have two lines in one column in the
datagrid coming from different sources!

I would like to turn the top time into a link!

EG:Have <%# Container.DataItem("header")%> as a link

<a href="default.aspx?id= <%# Container.DataItem("itemID")%>"><%#
Container.DataItem("header")%> </a>

This doesn't work but I wondered if there was a nother way to achieve the
same thing!

Thanks

---code---
<asp:TemplateColumn HeaderText="Event" HeaderStyle-Width="80%">
<ItemStyle HorizontalAlign="Left" Width="80%"></ItemStyle>
<ItemTemplate>
<b>
<%# Container.DataItem("header")%>
</b><br>
<%# Container.DataItem("EventLocation")%>
</ItemTemplate>
</asp:TemplateColumn>
 
Tim::.. said:
Can someone please tell me how I turn an ItemTemplate into a link? I don't
what to use a HyperlinkColumn as I have two lines in one column in the
datagrid coming from different sources!

I would like to turn the top time into a link!

EG:Have <%# Container.DataItem("header")%> as a link

<a href="default.aspx?id= <%# Container.DataItem("itemID")%>"><%#
Container.DataItem("header")%> </a>

Here is how I do mine with a Hyperlink (go directly to another page),
ImageButton and Linkbutton (go to a function then you may or may not go to
another page)

<asp:TemplateColumn SortExpression="JobTitle" ItemStyle-VerticalAlign="Top"
HeaderText="Job Title">
<itemtemplate>
<asp:hyperlink text='<%# Container.DataItem("JobTitle")%>'
NavigateUrl='<%# "displayPosition.aspx?PositionID=" &
Container.DataItem("PositionID") %>' runat="server" /><br>
</itemtemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Resume" ItemStyle-CssClass="CenterCell"
ItemStyle-Width="60px">
<itemtemplate>
<asp:ImageButton id="Date"
visible="false"
OnClick="Resume_Click"
width="12px"
Height="12px"
ImageUrl="../../images/taskCompleted2.gif"
ToolTip='<%# Container.DataItem("Date")%>'
runat="server"/>
</itemtemplate>
</asp:TemplateColumn>

<asp:TemplateColumn ItemStyle-Width="45" FooterStyle-Width="45">
<itemtemplate>
<asp:LinkButton CommandName="Delete" Text="Delete" ID="btnDelete"
runat="server" />
</itemtemplate>
<asp:TemplateColumn

This one is handled would be handled by the DataGrids events (testing for
e.commandname="Delete" in this case):
.....
OnItemCreated="DataGrid_ItemCreated"
OnItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
OnEditCommand="DataEdit"
OnCancelCommand="DataCancel"
OnUpdateCommand="DataUpdate"
.....

<asp:TemplateColumn ItemStyle-Width="45" FooterStyle-Width="45">
<itemtemplate>
<asp:LinkButton Text="Delete" OnClick="Delete_Click" ID="btnDelete"
runat="server" />
</itemtemplate>
</asp:TemplateColumn>

This one would be handled by the "Delete_Click" event.

HTH

Tom
 

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

Back
Top