datalist inside a tabcontainer does't shows links

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sara10
    New Member
    • Feb 2010
    • 3

    datalist inside a tabcontainer does't shows links

    hi,
    i have a datalist inside a tabcontainer. I need to display data from database into the datalist as hyperlink, and when i click on any of that link it should navigate to another page and to display data according to that link.

    i have tried and it works fine when the datalist is not placed inside the tabcontainer, but when i put datalist inside tab container the "OnItemdataboun d " event does't fire.
    here is the code.
    --------------------C# File------------------------------------
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
     DataSet myds = new DataSet();
            da.Fill(myds);
            DataList1.DataSource = myds;
            DataList1.DataBind();
    }
    protected void datalist1(object sender, DataListItemEventArgs e)
        {
            HyperLink hpclk = (HyperLink)(e.Item.FindControl("hlpnews"));
            
            hpclk.NavigateUrl = "~/NewFolder1/main.aspx?Username="+ hpclk.Text;
        }
    ------------in .aspx file---------------------------------------------------
    Code:
      <asp:DataList ID="DataList1" runat="server" BorderColor = "Black" OnItemDataBound="datalist1">
        <ItemTemplate>
                     <asp:HyperLink runat ="server" ID="hlpnews" text='<%#DataBinder.Eval(Container.DataItem,"Username") %>' >
                     </asp:HyperLink>
                  </ItemTemplate>
    
               </asp:DataList>
    ------------------------------------------------------------------------------
    the above code works fine for a datalist outside the tabcontainer, but does't work for 1 inside the container.
    any one can help plz,
    Last edited by tlhintoq; Feb 14 '10, 07:40 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • sara10
      New Member
      • Feb 2010
      • 3

      #3
      can any one help please...why isn't "Onitemdataboun d" event firing??..

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Hmmm, I'm not 100% on this but I think I know what's wrong.

        When a control fires an event it needs to be handled by it's parent container....th e parent container in your case may have become the TabContainer and so your Page code will never see it fire. I experienced this a while ago when I was trying to handle the onclick event for LinkButtons in a custom class that implemented the ITemplate interface...the LinkButton's click event was being fired to the class and it was never getting to my page code...so I had to re-raise the event from there.

        I don't know why the TabContainer would do this...but it's the only reason I can think of that "might" be causing this problem.

        I am going to recommend that you move the code in the DataBound event out of your C# code and instead use the DataBinding syntax to declaratively do this.

        For example:
        Code:
        <asp:DataList ID="DataList1" runat="server" BorderColor = "Black">
          <ItemTemplate>
            <asp:HyperLink runat ="server" 
                 ID="hlpnews"
                 text='<%#DataBinder.Eval(Container.DataItem,"Username") %>' 
                 NavigateUrl='~/NewFolder1/main.aspx?Username=<%#DataBinder.Eval(Container.DataItem,"Username") %>' >
             </asp:HyperLink>
         </ItemTemplate>
        </asp:DataList>
        I don't know if you can do this with the NavigateUrl property...but give it a try and let me know how things go.

        -Frinny

        Comment

        Working...