By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,775 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,775 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

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" <da**********@ca.trader.com> wrote in message news:e0*************************@posting.google.co m...
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>

Nov 18 '05 #2

P: n/a
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!
Nov 18 '05 #3

P: n/a

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!
Nov 18 '05 #4

P: n/a
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" <id***@attenua.com> wrote in message news:eZ**************@TK2MSFTNGP11.phx.gbl...
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!

Nov 18 '05 #5

P: n/a
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!
Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.