Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Pleas see to below code:
C#
System.Data.DataTable dt = new System.Data.DataTable();

        dt.Columns.Add(new System.Data.DataColumn("id", typeof(int)));
        dt.Columns.Add(new System.Data.DataColumn("name", typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn("samplenum", typeof(int)));

        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        SqlCommand cmd = new SqlCommand("select * from GRIDTESTDETAILS", conn);
        SqlDataReader dr = cmd.ExecuteReader();

       // DataRow drw = new DataRow();

        TableRow tr = new TableRow();
        while (dr.Read())
        {
            
            string link = "<a href=\"#\" >" + dr[0] + "</a>";
            dt.Rows.Add(dr[0],link, dr[2]);
        }

        gvSample.DataSource = dt; // it is gridview in asp.net
        gvSample.DataBind();

        conn.Close();


Code is executing perfectly by fetching data from database
But the problem is below output
id	       name	      samplenum
21	<a href="#" >21</a>	255
22	<a href="#" >22</a>	26
23	<a href="#" >23</a>	26
24	<a href="#" >24</a>	255
25	<a href="#" >25</a>	255

Wats going wrong? I want above <a> as Hyperlink.
Please Help me.
Thanks.
Posted
Updated 3-Nov-12 21:40pm
v2
Comments
Sandeep Mewara 4-Nov-12 3:41am    
You say you get a-href as written. Now what is the issue?
amit Baswa 4-Nov-12 3:42am    
I want it to be appear as 'link' not as 'html code'

Ok, as you say, it looks like HTML is getting encoded before binding. You need to decode it in RowDataBound method. Example:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {

    if (e.Row.RowType == DataControlRowType.DataRow) {
       e.Row.Cells[columnIndex].Text = Server.HtmlDecode(e.Row.Cells[columnIndex].Text);
    }
}
 
Share this answer
 
Comments
amit Baswa 4-Nov-12 3:59am    
Excellent Answer.
Thanks a Lot. You solved my problem.
Sandeep Mewara 4-Nov-12 4:03am    
Welcome.
directly you bind it for that problem is Coming.

if u take a coloumn add link button and then bind with data grid Your Problem will solve.

if need any information just mail me
 
Share this answer
 
Comments
amit Baswa 4-Nov-12 3:52am    
I didn't got what you said above.
Can you please explain with example?

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