LinkButton in Repeater control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Larsen [CPH]

    LinkButton in Repeater control

    Hi,

    The following sample shows a LinkButton in the HeaderTemplate of a Repeater
    control.

    The problem is that i'm not able to access the linkbutton in code (in the cs
    file) as long as the linkbutton stays in the
    repeater control - see the following line:
    testLink.Comman dArgument = "just testing"; or testLink.Text = "Some new
    text";

    How do i dynamically change the properties of the LinkButton in runtime ??

    Thank you in advance.
    BR
    Peter



    Sample code:

    <asp:Repeater id="dataRepeate r" runat="server">
    <HeaderTemplate >
    Header data
    <table class="repeat_t able">
    <tr id="rowHeadLine ">
    <td id="fieldHeadLi ne">
    <asp:LinkButt on
    ID="testLink"
    runat="server"
    OnClick="testfu nc"
    Text="hit me">
    </asp:LinkButton>
    </td>
    </tr>
    </HeaderTemplate>
    <ItemTemplate >
    ...




  • Lloyd Sheen

    #2
    Re: LinkButton in Repeater control

    Peter Larsen [CPH] wrote:
    Hi,
    >
    The following sample shows a LinkButton in the HeaderTemplate of a Repeater
    control.
    >
    The problem is that i'm not able to access the linkbutton in code (in the cs
    file) as long as the linkbutton stays in the
    repeater control - see the following line:
    testLink.Comman dArgument = "just testing"; or testLink.Text = "Some new
    text";
    >
    How do i dynamically change the properties of the LinkButton in runtime ??
    >
    Thank you in advance.
    BR
    Peter
    >
    >
    >
    Sample code:
    >
    <asp:Repeater id="dataRepeate r" runat="server">
    <HeaderTemplate >
    Header data
    <table class="repeat_t able">
    <tr id="rowHeadLine ">
    <td id="fieldHeadLi ne">
    <asp:LinkButt on
    ID="testLink"
    runat="server"
    OnClick="testfu nc"
    Text="hit me">
    </asp:LinkButton>
    </td>
    </tr>
    </HeaderTemplate>
    <ItemTemplate >
    ...
    >
    >
    >
    >
    You want to handle the ItemDataBound event for dataRepeater.

    In the event handler check e.Item.ItemType and when it is Header you can
    do a e.Item.FindCont rol("testLink") to get a reference to the
    LinkButton. From there change what you need.

    Hope this helps
    LS

    Comment

    • Steven Cheng [MSFT]

      #3
      RE: LinkButton in Repeater control

      Hi Peter,

      As other member suggested, you can register the "ItemCreate d" event of
      Repeater control and then use "FindContro l" to locate the linkbutton. Here
      is a complete example (with aspx and codebehind) which demonstrate this:

      ============asp x =============== ==
      <form id="form1" runat="server">
      <div>

      <asp:Repeater id="dataRepeate r" runat="server"
      onitemcreated=" dataRepeater_It emCreated">
      <HeaderTemplate >
      Header data
      <table class="repeat_t able">
      <tr id="rowHeadLine ">
      <td id="fieldHeadLi ne">
      <asp:LinkButt on
      ID="testLink"
      runat="server"

      Text="hit me">
      </asp:LinkButton>
      </td>
      </tr>
      </HeaderTemplate>
      <ItemTemplate >
      <tr>
      <td><hr />item</td>
      </tr>
      </ItemTemplate>
      <FooterTemplate >
      </table>
      </FooterTemplate>

      </asp:Repeater>


      </div>
      </form>

      ==============c ode behind========= ====
      public partial class RepeaterPage : System.Web.UI.P age
      {
      protected void Page_Load(objec t sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      string[] items = new string[] { "aaa", "bbb", "ccc", "ddd" };

      dataRepeater.Da taSource = items;
      dataRepeater.Da taBind();
      }
      }
      protected void dataRepeater_It emCreated(objec t sender,
      RepeaterItemEve ntArgs e)
      {
      if (e.Item.ItemTyp e == ListItemType.He ader)
      {
      LinkButton lbtn = e.Item.FindCont rol("testLink") as LinkButton;

      if (lbtn != null)
      {
      lbtn.CommandNam e = "Display"; lbtn.CommandArg ument =
      "argument";
      lbtn.Click += delegate
      {
      Response.Write( "<br/>LinkButton clicked");
      };

      }
      }
      }
      }
      =============== ===========

      Hope this helps.

      Sincerely,

      Steven Cheng

      Microsoft MSDN Online Support Lead


      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      http://msdn.microsoft.com/en-us/subs...#notifications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://support.microsoft.com/select/...tance&ln=en-us.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.


      --------------------
      >From: "Peter Larsen [CPH]" <PeterLarsen@co mmunity.nospam>
      >Subject: LinkButton in Repeater control
      >Date: Thu, 21 Aug 2008 23:11:03 +0200
      >Hi,
      >
      >The following sample shows a LinkButton in the HeaderTemplate of a
      Repeater
      >control.
      >
      >The problem is that i'm not able to access the linkbutton in code (in the
      cs
      >file) as long as the linkbutton stays in the
      >repeater control - see the following line:
      testLink.Comman dArgument = "just testing"; or testLink.Text = "Some
      new
      >text";
      >
      >How do i dynamically change the properties of the LinkButton in runtime ??
      >
      >Thank you in advance.
      >BR
      >Peter
      >
      >
      >
      >Sample code:
      >
      ><asp:Repeate r id="dataRepeate r" runat="server">
      <HeaderTemplate >
      Header data
      <table class="repeat_t able">
      <tr id="rowHeadLine ">
      <td id="fieldHeadLi ne">
      <asp:LinkButt on
      ID="testLink"
      runat="server"
      OnClick="testfu nc"
      Text="hit me">
      </asp:LinkButton>
      </td>
      </tr>
      </HeaderTemplate>
      <ItemTemplate >
      ...
      >
      >
      >
      >
      >

      Comment

      • Peter Larsen [CPH]

        #4
        Re: LinkButton in Repeater control

        Hi Steven,

        Thank you for the solution.
        It seems to be what i need.

        BR
        Peter


        "Steven Cheng [MSFT]" <stcheng@online .microsoft.comw rote in message
        news:YgclaiABJH A.5744@TK2MSFTN GHUB02.phx.gbl. ..
        Hi Peter,
        >
        As other member suggested, you can register the "ItemCreate d" event of
        Repeater control and then use "FindContro l" to locate the linkbutton. Here
        is a complete example (with aspx and codebehind) which demonstrate this:
        >
        ============asp x =============== ==
        <form id="form1" runat="server">
        <div>
        >
        <asp:Repeater id="dataRepeate r" runat="server"
        onitemcreated=" dataRepeater_It emCreated">
        <HeaderTemplate >
        Header data
        <table class="repeat_t able">
        <tr id="rowHeadLine ">
        <td id="fieldHeadLi ne">
        <asp:LinkButt on
        ID="testLink"
        runat="server"
        >
        Text="hit me">
        </asp:LinkButton>
        </td>
        </tr>
        </HeaderTemplate>
        <ItemTemplate >
        <tr>
        <td><hr />item</td>
        </tr>
        </ItemTemplate>
        <FooterTemplate >
        </table>
        </FooterTemplate>
        >
        </asp:Repeater>
        >
        >
        </div>
        </form>
        >
        ==============c ode behind========= ====
        public partial class RepeaterPage : System.Web.UI.P age
        {
        protected void Page_Load(objec t sender, EventArgs e)
        {
        if (!IsPostBack)
        {
        string[] items = new string[] { "aaa", "bbb", "ccc", "ddd" };
        >
        dataRepeater.Da taSource = items;
        dataRepeater.Da taBind();
        }
        }
        protected void dataRepeater_It emCreated(objec t sender,
        RepeaterItemEve ntArgs e)
        {
        if (e.Item.ItemTyp e == ListItemType.He ader)
        {
        LinkButton lbtn = e.Item.FindCont rol("testLink") as LinkButton;
        >
        if (lbtn != null)
        {
        lbtn.CommandNam e = "Display"; lbtn.CommandArg ument =
        "argument";
        lbtn.Click += delegate
        {
        Response.Write( "<br/>LinkButton clicked");
        };
        >
        }
        }
        }
        }
        =============== ===========
        >
        Hope this helps.
        >
        Sincerely,
        >
        Steven Cheng

        Comment

        • Peter Larsen [CPH]

          #5
          Re: LinkButton in Repeater control

          Hei Lloyd,

          Thank you for your answer to my question.

          BR
          Peter.



          "Lloyd Sheen" <a@b.cwrote in message
          news:%23b5CuV%2 3AJHA.4316@TK2M SFTNGP05.phx.gb l...
          >
          You want to handle the ItemDataBound event for dataRepeater.
          >
          In the event handler check e.Item.ItemType and when it is Header you can
          do a e.Item.FindCont rol("testLink") to get a reference to the LinkButton.
          From there change what you need.
          >
          Hope this helps
          LS

          Comment

          • Steven Cheng [MSFT]

            #6
            Re: LinkButton in Repeater control

            You're welcome Peter,

            I'm glad that it helps.

            Sincerely,

            Steven Cheng

            Microsoft MSDN Online Support Lead


            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.

            --------------------
            >From: "Peter Larsen [CPH]" <PeterLarsen@co mmunity.nospam>
            >References: <uZ$wsJ9AJHA.60 16@TK2MSFTNGP04 .phx.gbl>
            <YgclaiABJHA.57 44@TK2MSFTNGHUB 02.phx.gbl>
            >Subject: Re: LinkButton in Repeater control
            >Date: Fri, 22 Aug 2008 09:37:46 +0200
            >
            >Hi Steven,
            >
            >Thank you for the solution.
            >It seems to be what i need.
            >
            >BR
            >Peter
            >
            >
            >"Steven Cheng [MSFT]" <stcheng@online .microsoft.comw rote in message
            >news:YgclaiABJ HA.5744@TK2MSFT NGHUB02.phx.gbl ...
            >Hi Peter,
            >>
            >As other member suggested, you can register the "ItemCreate d" event of
            >Repeater control and then use "FindContro l" to locate the linkbutton.
            Here
            >is a complete example (with aspx and codebehind) which demonstrate this:
            >>
            >============as px =============== ==
            ><form id="form1" runat="server">
            > <div>
            >>
            > <asp:Repeater id="dataRepeate r" runat="server"
            > onitemcreated=" dataRepeater_It emCreated">
            > <HeaderTemplate >
            > Header data
            > <table class="repeat_t able">
            > <tr id="rowHeadLine ">
            > <td id="fieldHeadLi ne">
            > <asp:LinkButt on
            > ID="testLink"
            > runat="server"
            >>
            > Text="hit me">
            > </asp:LinkButton>
            > </td>
            > </tr>
            > </HeaderTemplate>
            > <ItemTemplate >
            > <tr>
            > <td><hr />item</td>
            > </tr>
            > </ItemTemplate>
            > <FooterTemplate >
            > </table>
            > </FooterTemplate>
            >>
            > </asp:Repeater>
            >>
            >>
            > </div>
            > </form>
            >>
            >============== code behind========= ====
            >public partial class RepeaterPage : System.Web.UI.P age
            >{
            > protected void Page_Load(objec t sender, EventArgs e)
            > {
            > if (!IsPostBack)
            > {
            > string[] items = new string[] { "aaa", "bbb", "ccc", "ddd" };
            >>
            > dataRepeater.Da taSource = items;
            > dataRepeater.Da taBind();
            > }
            > }
            > protected void dataRepeater_It emCreated(objec t sender,
            >RepeaterItemEv entArgs e)
            > {
            > if (e.Item.ItemTyp e == ListItemType.He ader)
            > {
            > LinkButton lbtn = e.Item.FindCont rol("testLink") as
            LinkButton;
            >>
            > if (lbtn != null)
            > {
            > lbtn.CommandNam e = "Display"; lbtn.CommandArg ument =
            >"argument";
            > lbtn.Click += delegate
            > {
            > Response.Write( "<br/>LinkButton clicked");
            > };
            >>
            > }
            > }
            > }
            >}
            >============== ============
            >>
            >Hope this helps.
            >>
            >Sincerely,
            >>
            >Steven Cheng
            >
            >
            >

            Comment

            Working...