Please HELP! Need to access textbox control values within a repeater control

Discussion in 'ASP .Net' started by Darren Smith, May 6, 2004.

  1. Darren Smith

    Darren Smith Guest

    Hi There,

    I have a shopping cart app that displays products along with a textbox
    (to enter quantity) and an image button to add the item to the
    shopping cart. Please explain why my below Button_Click procedure
    does not retrieve the value of the textbox where the button was
    clicked.

    Thanks in Advance,

    Darren




    Sub Button_Click(s as Object, e as ImageClickEventArgs)
    Dim Btn As System.Web.UI.WebControls.ImageButton = s
    Dim iId as integer
    iId=Btn.CommandArgument
    Response.write (iId)
    Dim tb as System.Web.UI.WebControls.TextBox =
    btn.Parent.FindControl("txtValue")
    Response.write ("TextBox Value=" & tb.Text)
    End Sub
    -------------------------------------------------------
    <form id="frmProducts" runat="server">
    <asp:repeater id="rptProducts" Runat="server">
    <ItemTemplate>

    a href="ProductInfo.aspx?id=<%# DataBinder.Eval(Container.DataItem,
    "prodid") %>"><%# DataBinder.Eval(Container.DataItem, "prodname")
    %></a></b></td>

    <%# DataBinder.Eval(Container.DataItem, "catdesc") %></td>

    <%# formatcurrency(DataBinder.Eval(Container.DataItem,
    "retailprice"),2) %>

    member price:&nbsp;<b><%#
    formatcurrency(DataBinder.Eval(Container.DataItem, "memberprice"),2)
    %></b></td>


    <asp:TextBox runat="server" width="20" name="txtValue" id="txtValue"
    CommandArgument=<%# DataBinder.Eval(Container.DataItem, "prodid") %>
    />


    <asp:imagebutton id=btnAddCart CommandArgument=<%#
    DataBinder.Eval(Container.DataItem, "prodid") %> BorderWidth="0"
    onclick=Button_Click Runat="server" ImageUrl="Frame/btnAdd.gif"/>

    </ItemTemplate>
    </asp:repeater>
     
    Darren Smith, May 6, 2004
    #1
    1. Advertising

  2. Darren Smith

    Darren Clark Guest

    Add OnItemCommand="Repeater_Select" to the repeater

    then in the code
    public void Repeater_Select( object source, RepeaterCommandEventArgs e )

    {

    }


    use the CommandArgument property of the imagebutton to pass thorugh the information you require..

    if you need multiple values then do the following
    CommandArgument='<%# DataBinder.Eval(Container,"DataItem."+ ITEMONE +","+ ITEMTWO") %>'

    then just split on that..
    string res = e.CommandArgument.ToString();

    string delimStr = ",";

    char [] delimiter = delimStr.ToCharArray();

    string[] vals = res.Split(delimiter);

    string s = vals[0].ToString();

    string x = vals[1].ToString();



    "Darren Smith" <> wrote in message news:...
    > Hi There,
    >
    > I have a shopping cart app that displays products along with a textbox
    > (to enter quantity) and an image button to add the item to the
    > shopping cart. Please explain why my below Button_Click procedure
    > does not retrieve the value of the textbox where the button was
    > clicked.
    >
    > Thanks in Advance,
    >
    > Darren
    >
    >
    >
    >
    > Sub Button_Click(s as Object, e as ImageClickEventArgs)
    > Dim Btn As System.Web.UI.WebControls.ImageButton = s
    > Dim iId as integer
    > iId=Btn.CommandArgument
    > Response.write (iId)
    > Dim tb as System.Web.UI.WebControls.TextBox =
    > btn.Parent.FindControl("txtValue")
    > Response.write ("TextBox Value=" & tb.Text)
    > End Sub
    > -------------------------------------------------------
    > <form id="frmProducts" runat="server">
    > <asp:repeater id="rptProducts" Runat="server">
    > <ItemTemplate>
    >
    > a href="ProductInfo.aspx?id=<%# DataBinder.Eval(Container.DataItem,
    > "prodid") %>"><%# DataBinder.Eval(Container.DataItem, "prodname")
    > %></a></b></td>
    >
    > <%# DataBinder.Eval(Container.DataItem, "catdesc") %></td>
    >
    > <%# formatcurrency(DataBinder.Eval(Container.DataItem,
    > "retailprice"),2) %>
    >
    > member price:&nbsp;<b><%#
    > formatcurrency(DataBinder.Eval(Container.DataItem, "memberprice"),2)
    > %></b></td>
    >
    >
    > <asp:TextBox runat="server" width="20" name="txtValue" id="txtValue"
    > CommandArgument=<%# DataBinder.Eval(Container.DataItem, "prodid") %>
    > />
    >
    >
    > <asp:imagebutton id=btnAddCart CommandArgument=<%#
    > DataBinder.Eval(Container.DataItem, "prodid") %> BorderWidth="0"
    > onclick=Button_Click Runat="server" ImageUrl="Frame/btnAdd.gif"/>
    >
    > </ItemTemplate>
    > </asp:repeater>
     
    Darren Clark, May 7, 2004
    #2
    1. Advertising

  3. Darren Smith

    dsmith Guest

    Hi Darren,

    Thanks for your prompt reply, most appreciated.

    public void Repeater_Select( object source, RepeaterCommandEventArgs e )

    {

    }

    Does the Repeater_Select Sub remain empty?

    commandargument='<%# DataBinder.Eval(Container,"DataItem."+ ITEMONE
    +","+ ITEMTWO") %>'

    Is the above commandargument added to the imagebutton?

    string res = e.CommandArgument.ToString();
    string delimStr = ",";
    char [] delimiter = delimStr.ToCharArray();
    string[] vals = res.Split(delimiter);
    string s = vals[0].ToString();
    string x = vals[1].ToString();

    Is the above code placed in the Repeater_Select or the ImageButton
    On_Click routine?

    Thanks,

    Darren





    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    dsmith, May 7, 2004
    #3
  4. Darren Smith

    dsmith Guest

    Sorry, one more thing...

    At which point does the routine pass the value of the quantity textbox?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    dsmith, May 7, 2004
    #4
  5. Darren Smith

    Darren Clark Guest

    I should have put this in before...
    Here is an example..

    <asp:Repeater Runat="server" ID="JobPosts" OnItemCommand="Repeater_Select">
    <p>
    <asp:imagebutton
    CommandArgument='<%# DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobData.FLD_JOB_ID) %>'
    CommandName='EditJob'
    id="EditJob" onmouseover="this.src ='../Images/editover.gif'"
    onmouseout="this.src ='../Images/editnorm.gif'" Runat="server"
    ImageUrl="../Images/editnorm.gif"
    AlternateText="Edit Job">
    </asp:imagebutton>
    </p>
    </asp:Repeater>


    When the imagebutton is clicked it will push the event up to the repeaters onitemcommand


    public void Repeater_Select( object source, RepeaterCommandEventArgs e )
    {
    ///<summary>
    /// THis is when a button is selected from inside the repeater.
    ///</summary>

    // Get the JobID and then send the user to the correct page.
    string JobID = e.CommandArgument.ToString();

    Session["JobID"] = e.CommandArgument.ToString();

    if (e.CommandName.ToString() == "JobResults")
    {
    Response.Redirect("JobResults.aspx");
    }
    else if(e.CommandName.ToString() == "EditJob")
    {
    Response.Redirect("EditJob.aspx");
    }
    else if (e.CommandName.ToString() == "ArchiveJob")
    {
    // this is used as the CommandArgument passess 2 values through as s delimtered string eg. val1,val2

    string res = e.CommandArgument.ToString();
    string delimStr = ",";
    char [] delimiter = delimStr.ToCharArray();
    string[] vals = res.Split(delimiter);
    string s = vals[0].ToString();
    string x = vals[1].ToString();
    int jobID = Convert.ToInt32(s);
    int status = Convert.ToInt32(x);
    JobManager man =new JobManager();
    man.UpdateJobStatus(jobID,status);
    }
    }



    "dsmith" <> wrote in message news:...
    > Hi Darren,
    >
    > Thanks for your prompt reply, most appreciated.
    >
    > public void Repeater_Select( object source, RepeaterCommandEventArgs e )
    >
    > {
    >
    > }
    >
    > Does the Repeater_Select Sub remain empty?
    >
    > commandargument='<%# DataBinder.Eval(Container,"DataItem."+ ITEMONE
    > +","+ ITEMTWO") %>'
    >
    > Is the above commandargument added to the imagebutton?
    >
    > string res = e.CommandArgument.ToString();
    > string delimStr = ",";
    > char [] delimiter = delimStr.ToCharArray();
    > string[] vals = res.Split(delimiter);
    > string s = vals[0].ToString();
    > string x = vals[1].ToString();
    >
    > Is the above code placed in the Repeater_Select or the ImageButton
    > On_Click routine?
    >
    > Thanks,
    >
    > Darren
    >
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Darren Clark, May 8, 2004
    #5
  6. Darren Smith

    dsmith Guest

    Worked like a charm. Thanks for your assistance.



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    dsmith, May 10, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabriël
    Replies:
    0
    Views:
    469
    Gabriël
    May 27, 2004
  2. KatB
    Replies:
    0
    Views:
    447
  3. Replies:
    4
    Views:
    9,259
  4. KK
    Replies:
    2
    Views:
    592
    Big Brian
    Oct 14, 2003
  5. Jaime Stuardo

    How to access a server control within a repeater control

    Jaime Stuardo, Aug 19, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    169
    Jaime Stuardo
    Aug 19, 2006
Loading...

Share This Page