How to Databind a GridView through a Hyperlink

Last post 10-08-2008 4:20 AM by Qin Dian Tang - MSFT. 3 replies.

Sort Posts:

  • How to Databind a GridView through a Hyperlink

    10-04-2008, 4:15 PM
    • Member
      point Member
    • tah33777
    • Member since 10-04-2008, 8:03 PM
    • Posts 2

    Hii

     I am in need of a method to databind a gridview when a the user clicks on either hyperlink on the details view

     

     

    <asp:DetailsView ID="ProductInfo" runat="server" CellPadding="4" 
    
    ForeColor="#333333" GridLines="None"
    
    AutoGenerateRows="False" DataSourceID="" CssClass="style2" 
    
    
    
    style="z-index: 1; width: 268px; height: 268px; position: absolute; top: 89px; left: 13px">
    
    
    <Fields> 
    
    
    <asp:HyperLinkField DataTextField="AlQuozS" HeaderText="Al Quoz Showroom" NavigateUrl="javascript:alert('Description')"/> 
    
    <asp:HyperLinkField DataTextField="AlQuozW" HeaderText="Al Quoz Warehouse" NavigateUrl="javascript:alert('Description')"/>
    
    <asp:HyperLinkField DataTextField="SharjahS" HeaderText="Sharjah Showroom" NavigateUrl="javascript:alert('Description')"/>
    
    </Fields>
    
    
    
    </asp:DetailsView> 
    
    
     
     
  • Re: How to Databind a GridView through a Hyperlink

    10-04-2008, 7:01 PM
    • Member
      652 point Member
    • pmourfield
    • Member since 10-11-2005, 2:06 PM
    • Posts 109

    Hi,

     Can you provide a little more detail please about what you're trying to accomplish?

    Pete

    Sincerely,
    Peter Mourfield
    www.mourfield.com

    Please remember to click “Mark as Answer” on the post that helps you.
  • Re: How to Databind a GridView through a Hyperlink

    10-05-2008, 1:59 AM
    • Member
      point Member
    • tah33777
    • Member since 10-04-2008, 8:03 PM
    • Posts 2

    what i want to see is

    When the user clicks on any hyperlinkfield, the application would use datatextfield as a parameter that would be supplied to the DataSource and henceforth DataBind which would show a gridview

     

    I hope this helps

  • Re: How to Databind a GridView through a Hyperlink

    10-08-2008, 4:20 AM
    Answer

    Hi tah33777,

    If you use HyperLinkField, it passes parameter as querystring in url. It is more suitable for separate page. If you want to bind GridView in the same page, you can use LinkButton instead. I think you'd better use LinkButton here.

    For example,

    <asp:TemplateField headerText="Al Quoz Showroom">
                <ItemTemplate>
                  <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("AlQuozS") %>' CommandArgument='<%# Eval("AlQuozS") %>' CommandName="Bind"></asp:LinkButton>
                </ItemTemplate>
    </asp:TemplateField>

    Then handle ItemCommand event of DetailsView:

    protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            if (e.CommandName == "Bind")
            {
                string AlQuozS = e.CommandArgument.ToString();
                //use it to do databind
            }
        }

    Thanks,

     

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (4 items)