Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2006, 07:04 AM
Authorized User
 
Join Date: Jul 2005
Location: Pune, Maharasthra, India.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default How could i store a link in a DataRow in VC# 2005?

Hello all,

In VC# 2005, I want to store a link to a page say Edit.aspx on a DataRow object and i used the following code:

protected void Page_Load(object sender, EventArgs e)
{
DataTable dtbl = new DataTable();

DataColumn dcol = new DataColumn("LINK");

dtbl.Columns.Add(dcol);

DataRow dRow;

dRow = dtbl.NewRow();

dRow[0]= "<a href = '../EventsCalendar/Edit.aspx '>" + "Edit" + "</a>";

dtbl.Rows.Add(dRow);

grdvw.DataSource = dtbl;
grdvw.DataBind();

}

There is a GridView Control also called grdvw where Iam binding my DataTable object Called dtbl to this GridView Control.The code is,

grdvw.DataSource = dtbl;
grdvw.DataBind();

Now the problem with this code is the variable dRow[0] is storing the whole string in place of storing only Edit as hyperlink.

I mean to say dRow[0] == "<a href = '../EventsCalendar/Edit.aspx '>" + Edit + "</a>";

Due to this problem Iam not getting the Edit link on my Gridview 0th Column cell. Instead of Edit link Iam getting the whole string which is <a href = '../EventsCalendar/Edit.aspx '>Edit</a>.

It seems that html tags <a>, and single and double quotes are not recognised by this program.

CAN ANYONE HELP ME OUT to get the desired result on my Gridview control.
Please do remember that I want to store the value first on dRow[0].
So is there any method by which I can store the Edit link on dRow[0].

Waiting for your early response.
Please Do reply very soon. Iam in need of urgent help!!!!


 
Old June 9th, 2006, 07:17 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

By default in the GridView, the data is HtmlEncoded, so you get the HTML text equivalent of the value.

If you set HtmlEncode="False" on the GridView's column, it should work.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 12th, 2006, 04:51 AM
Authorized User
 
Join Date: Jul 2005
Location: Pune, Maharasthra, India.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all thanks for replying my post.
setting HtmlEncode="False" on the GridView's column is working fine on the Gridview' column but I want to do this all in the runtime.I mean I want to set HtmlEncode="False" in a code. Is there any method to do so as i have tried out but didn't got succeeded.


Thanks and regards

 
Old June 12th, 2006, 05:20 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

You can use the template item and in this add the hyperlink and in hyperlink specify the url where you want to sent the page

(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is how you got it
 
Old June 12th, 2006, 01:34 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Lalit Pradhan,

If you're doing it programmatically, you can cast the appropriate GridView column to an appropriate type, like a BoundColumn and then set the HtmlEncode property:

      BoundField myField = (BoundField) GridView1.Columns[0];
      myField.HtmlEncode = true;

This code assumes that the first column in your GridView is a BoundColumn.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old June 14th, 2006, 08:59 AM
Authorized User
 
Join Date: Jun 2005
Location: , , Philippines.
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default

Heres my solution to this:
http://p2p.wrox.com/topic.asp?TOPIC_ID=45307

Aldwin Enriquez
"Dont you ever give up!"
 
Old June 15th, 2006, 05:30 AM
Authorized User
 
Join Date: Jul 2005
Location: Pune, Maharasthra, India.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Again Heartiest thanks and full points to Mr.Imar.

I got the solution through your previous reply.What i did in my code
is just created BoundField columns for my GridView control and set the DataField property of the columns to the columns of my DataTable object dtbl which i created programmatically.I also set HtmlEncode property to false over there which is now perfectly working.

Hoping for more solutions from your side when needed.:)




 
Old June 16th, 2006, 07:44 AM
Authorized User
 
Join Date: Jul 2005
Location: Pune, Maharasthra, India.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello everyone and specially Mr. Imar,

My hyperlink problem has been solved but I don't want to display underline on my hyperlink item.As you already know Iam creating this hyperlink item at the runtime.So there is no use of hyperlink Field for which I can set ControlStyle Font-Underline property to false (<ControlStyle Font-Underline="False" />) as in the following code.

(This is just a code for better understanding the problem. Its not my code.)

<asp:HyperLinkField Target="_blank" DataTextField="Title" SortExpression="Title" HeaderText="Title" DataNavigateUrlFields="Link">
                        <ItemStyle ForeColor="Blue" />
                        <HeaderStyle HorizontalAlign="Center" />
                        <ControlStyle Font-Underline="False" />
                    </asp:HyperLinkField>

I want to display the underline on a hyperlink Item( or data) only when I hover a mouse over it.Rest of the times I would like to view it without underline.

I have tried out all the properties regarding GridViewRow and TableCell but all the time the hyperlink item which I dynamically created displayed on the GridView column with underline.
(like this [u]link</u>)which is not my requirement.

Please help me out as soon as possible.Again Its very urgent.
Waiting for your early response.

:)
 
Old June 18th, 2006, 07:36 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Of course it's urgent. It's always urgent. However, I don't think that adding that will speed up any response. When people have time, they'll answer. When they don't, they won't. You can't expect them to make your problem theirs.... ;)

Anyway, you can simply do this with some CSS. Add a CssClass to the hyperlink, like this:

<asp:HyperLinkField>
  <ItemStyle CssClass="MyClass" />
</asp:HyperLinkField>

Then in your CSS file, you can define style definitions for MyClass and MyClass:hover like this:

.MyClass
{
  text-decoration: none;
}

.MyClass:hover
{
  text-decoration: underline;
}

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Come Together by Primal Scream (Track 12 from the album: Trainspotting OMPST CD 2) What's This?
 
Old June 20th, 2006, 12:44 AM
Authorized User
 
Join Date: Jul 2005
Location: Pune, Maharasthra, India.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, you have a good sense of humour apart from excellent programming skills.I really appreciate it.
Imar, First of all heartiest thanks for spending your valuable time on looking at my problems.I want to tell you that Iam not using HyperLinkField in my code.Instead hyperlink item gets created at runtime and also it is not necessary that all items will be hyperlink item. I have created the stylesheet as per your instruction and also tried to apply it on the gridview column where link is getting created dynamically but still the hyperlink item is underlined.Iam sending you the code how I applied your code snippet to my code for your consideration.

You sent me the following code snippet:

Anyway, you can simply do this with some CSS. Add a CssClass to the
hyperlink, like this:

<asp:HyperLinkField>
  <ItemStyle CssClass="MyClass" />
</asp:HyperLinkField>

Then in your CSS file, you can define style definitions for MyClass and
MyClass:hover like this:

MyClass
{
  text-decoration: none;
}

MyClass:hover
{
  text-decoration: underline;
}

Though I created this stylesheet class in my project and
I applied your ItemStyle-CssClass="MyClass" to my code in the following manner

<asp:GridView ID="grdvw" runat="server" HeaderStyle-BackColor="Azure" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="LINK" HeaderText="LINK" HtmlEncode="false" ItemStyle-CssClass="MyClass" />

              </Columns>

But its not working perfectly.

This is Additional.
Imar Iam a beginner in ASP.NET 2.0 and C# but the company on which Iam working expecting a lot from my side in spite of knowing that Iam a beginner.The timelines are very short but i need to any how meet that.Though I have been with VB.NET beta version for a while but i dont have that much programming skills. All I want to ask you is that is there any method or learning technique by which I can learn ASP.NET 2.0 with C# in a very quick and efficient manner with implementation knowledge of all the key concepts of web and ASP.NET 2.0 programming.If there is any good book in your point of view feel free to mention it. Apart from all this, I also need your expert guidance which I hope you will keep on providing me.In fact if you are in India, I would like to take tuitions from you.

Pls do reply and again thanks for sparing your valuable time in reading this post.

regards,

Lalit ;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move the mouse in VC++ 2005 marcelo39 Visual C++ 0 April 25th, 2008 09:36 AM
my problem with vc++2005 Anahita Visual C++ 2005 0 March 27th, 2007 09:22 AM
Please, need help with VC 2005 express IDE! pghTech Visual C++ 2005 0 June 27th, 2006 06:40 PM
How could i store a link in a DataRow in VC# 2005? Lalit Pradhan C# 2005 0 June 9th, 2006 07:10 AM
vc++2003 can't link properly. Kilka Visual C++ 1 March 15th, 2005 06:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.