Make hyperlink appear in a datagrid cell

L

Lynn

Hi

I have a datagrid, on a form, which contains a custom column style that converts a data grid text field into a linklabel. The problem I am having is that the link doesn't appear until the cell is clicked. Is there a way to have the link appear when the datagrid is loaded

Thanks
Lynn
 
J

Jeffrey Tan[MSFT]

Hi Lynn,

Based on my understanding, you want to add a column with is hyperlink class
in your datagrid control.

Asp.net DataGrid control has a build-in HyperLinkColumn, you can just
leverage it to display a column of hyperlinks in datagrid, Like this:

private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
DataSet ds=new DataSet ();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=");
adapter.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
}

//Html View Code
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 64px" runat="server"
Width="400px" Height="232px">
<Columns>
<asp:HyperLinkColumn DataTextField="job_desc"
HeaderText="HyperLinkColumn"
NavigateUrl="http://msdn.microsoft.com"></asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>

It should work as you expected.

Surely, you can just TemplateColumn to add HyperLink control in that
column, this will give more control on the behavior, like this:
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 64px" runat="server"
Width="400px" Height="232px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink ID="hl" Runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "job_desc")%>'
NavigateUrl="http://msdn.microsoft.com"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Lynn,

Does my reply make sense to you? Do you still have any concern on this
issue?

Please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
L

lynn

Jeffrey

I had attempted two replies to you last week. But for some reason, the replies are not being posted. Any how, here is my question again. How do I apply your response to a datagrid that is placed on a Windows form instead of an Asp.Net datagrid control

Thanks
Lyn

----- "Jeffrey Tan[MSFT]" wrote: ----

Hi Lynn

Does my reply make sense to you? Do you still have any concern on this
issue

Please feel free to post. Thank

Best regards
Jeffrey Ta
Microsoft Online Partner Suppor
Get Secure! - www.microsoft.com/securit
This posting is provided "as is" with no warranties and confers no rights
 
J

Jeffrey Tan[MSFT]

Hi Lynn,

Thanks for your feedback.

Windows Form datagrid is completely different from web form datagrid
control.

For winform datagrid, you should handle its DataGridColumnStyle class,
please refer to 2 articles below:

http://www.syncfusion.com/faq/winforms/search/480.asp
http://www.codeproject.com/cs/miscctrl/datagridcomboboxcolumn.asp?target=Dat
aGridColumnStyle

Also, for winform datagrid question, I suggest you pasted it in
microsoft.public.dotnet.framework.windowsforms group. My colleague will
help you there.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Lynn,

Does my reply make sense to you? Do you still have any concern on this
issue?

Please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
L

lynn

Thanks for your suggestions. I've posted a question under windows forms and I've gotten help from one of your partners

Lynn
 
J

Jeffrey Tan[MSFT]

Hi Lynn,

I am glad we can help you. If you have aspnet datagrid question, please
feel free to post here.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top