Click here to Skip to main content
14,698,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Gridview in my project. I have a column pur_no which is BoundField, which is displays datas from database. I want that field is like link field, How to do it,Please help me. For when I click that no, it is redirect to another page, How to do it, Please help me.

I want like following

pur_no
1
2
3
4
Posted

Hi ,
Try this
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
       <Columns>
           <asp:TemplateField>
               <ItemTemplate>                 
                        <a href= "<%# Eval("address") %>"  id="a1" > Click here</a>

               </ItemTemplate>
           </asp:TemplateField>
       </Columns>
   </asp:GridView>


if (!IsPostBack)
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("select * from test1", con))
                {
                    DataTable dt = new DataTable();
                    SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                    adpt.Fill(dt);
                   GridView1.DataSource = dt;
                  GridView1.DataBind();
                }
            } 
        }

Best Regards
M.Mitwalli
   
v3
You must have a look on this thread:
HyperLink in datagridview[^]
Here this question was solved, You will defiantly get some help from it.
   
Please go through the GridView class overall on what all features it provide. It exposes few column types, one them being 'Hyperlink' column.
Read: MSDN: Gridview Hyperlink column[^]
MSDN: Gridview[^]

Another sample: How to use HyperLinkField in GridView[^]
   
Comments
devausha 24-Apr-12 2:42am
   
Thank you for your Reply
Sandeep Mewara 24-Apr-12 3:01am
   
Welcome.

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