Click here to Skip to main content
16,015,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
How can I merge between three columns and the same time make the result as link in gridview

the code for merg is
XML
<asp:TemplateField HeaderText="Name" >
                    <ItemTemplate>

                            <%# Eval("FIRST_NAME") +""+  Eval("FATHER_NAME") +"" + Eval("FAMILY_NAME")%>

                    </ItemTemplate>



                </asp:TemplateField>




the code for hyperlink is:
<asp:HyperLinkField DataNavigateUrlFields="Name" HeaderText="Name" DataNavigateUrlFormatString="sch.aspx?ID={0}"  DataTextField="Name" Target="_blank"> </asp:HyperLinkField>

In another word, there is no field called (Name ) in the database. because it is a new coulmn appear after merged (firstName,fatherName and familyName)

Thanks
Posted
Updated 11-Apr-11 0:40am
v2

Use an ASP.net HyperLink control in the TemplateField's ItemTemplate

XML
<asp:TemplateField HeaderText="Name" >
<ItemTemplate>
        <asp:HyperLink ID="hypSomeLink" runat="server" Text='<%# Eval("FIRST_NAME") %>' />                 
</ItemTemplate>
</asp:TemplateField>
 
Share this answer
 
Comments
at all 11-Apr-11 6:53am    
But you put just First name, I want the whole name
Thanks
jim lahey 11-Apr-11 9:01am    
I know, I assumed you'd be able to work it out from the example..
at all 11-Apr-11 9:46am    
as I understand from you I put it as following:

<asp:TemplateField HeaderText="Name">

<itemtemplate>

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Name", "sch.aspx?ID={0}") %>'

Target="_blank" Text='<%# Eval("FIRST_NAME") +""+ Eval("FATHER_NAME") +"" + Eval("FAMILY_NAME")%>'>







But it gave this error again:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Name'

What is the problem now?
jim lahey 11-Apr-11 10:08am    
It means exactly what your error message says: the DataBinder is looking for a column called "Name" where there isn't one
at all 11-Apr-11 9:49am    
Sorry , the site hidden the closing tag
XML
Use Name Instead Of

select FIRST_NAME+FATHER_NAME+FAMILY_NAME as Name from table


<asp:HyperLink ID="hyp_Isfresher" NavigateUrl='<%#"Your Link %>'
                                                Text='<%#Eval("Name")%>' runat="server"></asp:HyperLink>


<ItemTemplate>
<%# Eval("Name")%>
 </ItemTemplate>
 
Share this answer
 
v2
Comments
at all 11-Apr-11 6:54am    
Did you mean that put the sql statment inside hyperlink tag?
Mahendra.p25 11-Apr-11 6:58am    
No, In Your SqlQuery when You are returning your values


select FIRST_NAME+FATHER_NAME+FAMILY_NAME as Name,Col2,Col3,Col4 from table
at all 11-Apr-11 7:03am    
Is there any soultion other than SqlQuery ,because I did not deal with it ?
thanks
Mahendra.p25 11-Apr-11 7:04am    
Just want to ask from where your are getting
FIRST_NAME , FATHER_NAME ,FAMILY_NAME
at all 11-Apr-11 7:11am    
Yes it is from SqlQuery , I know simple information about it not in advance
You use the datalist control:-
Now same as your
<ItemTemplate>
                            <%# Eval("FIRST_NAME") +""+  Eval("FATHER_NAME") +"" + Eval("FAMILY_NAME")%>
                    
e>
<a target="_balank" style="color:#0000FF;" href='<%# "sch.aspx?ID="+ DataBinder.Eval(Container.DataItem,"ID").Tostring() %>' shape="rect">View full size</a> 
</ItemTemplat>
 
Share this answer
 
v3
Comments
at all 11-Apr-11 6:56am    
Where is the hyperlink tag here?
Thanks
at all 11-Apr-11 6:58am    
ok sorry, I think there is problem in site the code not clear
Rakesh From Patna 11-Apr-11 7:02am    
i am use the anchor tag for hyperlink. now my tag is start form < a....
at all 11-Apr-11 7:16am    
Did you mean use tag a inesated of <hyperlinktag?>
Rakesh From Patna 11-Apr-11 7:17am    
You use the "< a" tag ...
this tag is use for hyperlink in html.
This is very much possible.Insert a gridview and take gridviewTasks..Then take Edit Colums in that. Disable autogenerate field in that and add some bondfields..Then click on edit template and add hyperlink
 
Share this answer
 
Comments
Mathews Davis 11-Apr-11 8:02am    
This is just basics..Sorry i didnt get ur que..
at all 11-Apr-11 9:54am    
the problem not in how make the hyperlink
the problem how can merg between tag of hyperlink and tag of ItemTemplate
sql query structure:-
Create table Detail
(
FIRST_NAME varchar(50),
FATHER_NAME varchar(50),
FAMILY_NAME varchar(50)
)

Insert into detail values('Prince','Rakesh','adkk')

//Default2.aspx page is
<pre lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DataList ID="DataList1" runat="server">
        <ItemTemplate>
        <%# DataBinder.Eval(Container.DataItem,"FIRST_NAME" ).ToString()%> + <%# DataBinder.Eval(Container.DataItem,"FATHER_NAME").ToString() %>
        + <%# DataBinder.Eval(Container.DataItem,"FAMILY_NAME").ToString() %>
        <a href= '<%# "default3.aspx?vID="+ DataBinder.Eval(Container.DataItem,"Name") %>'>Name</a>
        </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html

>



Now default2.aspx.cs is
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(//connection string);
        SqlDataAdapter adapter = new SqlDataAdapter("Select FIRST_NAME,FATHER_NAME,FAMILY_NAME,FIRST_NAME+FATHER_NAME+FAMILY_NAME as 'Name' from Detail", con);
        DataSet ds=new DataSet();
        adapter.Fill(ds);
        DataList1.DataSource = ds.Tables[0];
        DataList1.DataBind();
    }
}


now default3.aspx is
<pre lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html

>



NOw default3.aspx.cs is
C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //your code for reterive query string
    }
}


I hope your problem is solve. because above code is work successfully in my computer
 
Share this answer
 
v2
Comments
at all 11-Apr-11 9:51am    
I do n't know what is the problem it gave me
System.Web.UI.WebControls.DataControlFieldCollection must have items of type 'System.Web.UI.WebControls.DataControlField'. 'asp:DataList' is of type 'System.Web.UI.WebControls.DataList'
at all 11-Apr-11 9:52am    
I working on Vs 2010 is this problem and can not understand what is the Datalist?
Rakesh From Patna 12-Apr-11 3:33am    
Not knowledge of vs2010 because i only work with .net2.0 framework

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900