Make a field in Datagrid control as a hyperlink

Last post 11-07-2009 8:06 PM by headcaper. 3 replies.

Sort Posts:

  • Make a field in Datagrid control as a hyperlink

    11-05-2009, 9:45 PM
    • Member
      4 point Member
    • headcaper
    • Member since 10-22-2009, 8:29 PM
    • Posts 11

    I am reading two fields from a SQL database into a datagrid as in:

    Application           Part No

    App1                     1001

    App2                     1002

    etc.......

    Is it possible to make the Part No field selectable (or have as a hyperlink) so that a user can view down the list of the applications and then click on the Part No field to perform an action eg. go to a new page that provides details on the part or display a picture of the part?

    I know I can set up a seperate hyperlink column to do this but I don't like how it looks -

                   Application             Part No

    View           App1                   1001

    View           App2                   1002

    View           App3                   1003

    etc..

    Having a long column of hyperlinks / selects that say 'View' or 'Select' looks messy and over the top to me.

  • Re: Make a field in Datagrid control as a hyperlink

    11-05-2009, 11:22 PM
    Answer
    • Member
      613 point Member
    • harsh.cer
    • Member since 07-24-2009, 10:36 AM
    • Posts 94

    Hi,

     

    assign Commamnd name to Partno field and use Datagrid_rowcommand event for hyperlink on that field.

     

    try this

     

    Following link may help you.

    http://www.codersource.net/published/view/286/creating_dynamic_bound_and_template_columns_in_datagrid.aspx

    http://forums.asp.net/t/1111431.aspx

     

    http://www.codeproject.com/KB/webforms/GridView_DropDownList.aspx

     

     

    Thanks

    Harshal D.

    Software Engineer

    Remember to click “Mark as Answer” on the post If you get answer from my post(s) !
  • Re: Make a field in Datagrid control as a hyperlink

    11-06-2009, 1:16 AM
    Answer
    • Participant
      1,107 point Participant
    • brijmohans10
    • Member since 06-17-2009, 10:30 AM
    • India
    • Posts 231

    Hiii yes you can bind database data with hyperlink in a grid like this

    on product.aspx

     <ItemTemplate>
                <div >
                 <asp:HyperLink ID="hplProduct" ForeColor="Black" runat="server" Font-Bold="true" Font-Underline="true" NavigateUrl= '<%#"order.aspx?pid=" + (DataBinder.Eval(Container, "DataItem.ProductID"))%>'
                                    Text='<%#DataBinder.Eval(Container,"DataItem.ProductName") %>'></asp:HyperLink>
                  
                    </div>
                </ItemTemplate>

    on order.aspx.cs

     protected void Page_Load(object sender, EventArgs e)
        {
            // don't reload data during postbacks
            if (!IsPostBack)
            {
                PopulateControls();
               
            }
        }
        private void PopulateControls()
        {
            // Retrieve ProductID from the query string
            int productId = int.Parse(Request.QueryString["pid"]);
            // stores product details
    
            // Retrieve product details 
            objproduct = objproductDB.GetProductsbyProductID(productId);
      }




    Thanks
    brij
    Remember to click “Mark as Answer” on the post, if it helps you.
  • Re: Make a field in Datagrid control as a hyperlink

    11-07-2009, 8:06 PM
    • Member
      4 point Member
    • headcaper
    • Member since 10-22-2009, 8:29 PM
    • Posts 11

    Thank you both. 

Page 1 of 1 (4 items)