473,748 Members | 2,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find id in repeater

7 New Member
Hi!

Im currenty using a repeater to loop out all my data in my database and everything is working just great =) I just have a small problem.

how do I get wich id the item is from the database?
I cant put it in to a label,literal or something like that.
When I searched about it I found out that I should use something like
<asp:placeholde r /> but I dont know how to get it to work
Here's my code so far aspx:

Expand|Select|Wrap|Line Numbers
  1.      <asp:Repeater ID="repeater" runat="server">
  2.  
  3.             <ItemTemplate>
  4.                    </tr>
  5.                    <tr>
  6.                          <td>
  7.                         <img src="<%#DataBinder.Eval(Container.DataItem,"gdimg")%>" width="50px" height="50px" />                           
  8.                          </td>
  9.  
  10.                          <td>
  11.                         <%#DataBinder.Eval(Container.DataItem,"gdname")%>                           
  12.                          </td>
  13.  
  14.                     <td>
  15.                              <asp:textbox id="Textbox1" runat="server" MaxLength="2" Width="25" />/antal
  16.                      </td>
  17.                </tr>
  18.               <tr>
  19.  
  20.                       <td><asp:literal id="t" 
  21. text="<%#DataBinder.Eval(Container.DataItem,"id")%>" runat="server" visible="false" />
  22.                      <asp:
  23.                         <asp:button id="Button1" runat="server" text="Köp" onclick="Button1_Click" />
  24.                       </td>      
  25.         </ItemTemplate>          
  26.      </asp:Repeater>
  27.  
  28.    </tr> 
  29. </table>
My code behind:

Expand|Select|Wrap|Line Numbers
  1.     protected void Button1_Click(object sender, System.EventArgs e)
  2.     {
  3.         Button btn = sender as Button;
  4.         Literal idd = btn.Parent.FindControl("t") as Literal;
  5.         TextBox tb = btn.Parent.FindControl("TextBox1") as TextBox;
  6.         if (tb != null)
  7.         {
  8.             Database db = new Database(Server.MapPath("App_Data/DB.mdb"));
  9.             Response.Write(tb.Text);
  10.             Response.Write(idd.Text);
  11.         }
  12.     }
  13.  
  14.  
  15.  
  16.  
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.         if (Page.IsPostBack == false)
  20.         {
  21.             Database db = new Database(Server.MapPath("App_Data/DB.mdb"));
  22.  
  23.             repeater.DataSource = db.ExecuteQuery("SELECT * FROM goods ORDER BY gdtype ASC");
  24.             repeater.DataBind();
  25.  
  26.             db.Close();
  27.         }
  28.  
  29.  
  30.             if (Request.QueryString != null)
  31.             {
  32.                 Database db = new Database(Server.MapPath("App_Data/DB.mdb"));
  33.  
  34.                 string bokstav = Request.QueryString["rel"];
  35.  
  36.                 repeater.DataSource = db.ExecuteQuery("SELECT * FROM goods WHERE gdtype LIKE '"+bokstav+"%'");
  37.                 repeater.DataBind();
  38.  
  39.                 db.Close();
  40.             }
  41.  
  42.     }
as you can se Im trying to get the id of the specific item from goods when Im pressing the button. hard to send it with repeater, any ideas?

You don't have to answer =) just found it out :P I just puted it in a asp:textbox and instead
of writing it like this
<asp:Textbox ID="t" runat="server" Visible="false" Text="<%#DataBi nder.Eval(Conta iner.DataItem," id")%>" />

I simply changed it to this
<asp:Textbox ID="t" runat="server" Visible="false" Text='<%#DataBi nder.Eval(Conta iner.DataItem," id")%>' />

The only change I did were the quotion marks, changed my " " for ' '
so if you got the same problem try this out to =)
Apr 21 '09 #1
0 2280

Sign in to post your reply or Sign up for a free account.

Similar topics

0
5401
by: Ed Allan | last post by:
http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt >-----Original Message----- >Doh! The HTML has all been rendered . . . > >Right click on this link and select 'Save target as ..' >to get the code in a text file. > >Thanks - Ed >
4
34528
by: huzz | last post by:
I am trying to access a DropDownList control inside a repeater using ItemCommand as shown below but for some reason i can't access the DropDownList. When i step through the debug i get <undefine value> for the DropDownList What am i doing wrong? <asp:Repeater ID="Repeater1" Runat="server" OnItemDataBound="create_ddl" OnItemCommand="Repeater1_ItemCommand"> <HeaderTemplate>
1
320
by: huzz | last post by:
I have two repeaters in a page... how do i access textbox values of one repeater from another? for example if i have repeater 1: rptIssue repeater2: rptReturn I want to bind the textbox values from repeater1 in repeater2. Here is what i am donig.. but i can't access the repeater1 controls in repeater2: .. public void rptReturn_ItemDataBound(object s, RepeaterItemEventArgs e)
2
1909
by: mark | last post by:
(not sure if this is the correct group) My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater to work just fine, as long as it's not nested within the first repeater. If it is nested within the first repeater, I don't get any data. If I put the second repeater as a separate repeater, not nested, it works fine. Here's my actual code,...
2
1914
by: GD | last post by:
I'd like to use a Repeater to display data coming back from a cross-tab report. Because it's a cross-tab, I generally don't know how many columns are coming back. They do follow a certain format: e.g. CompanyName, c1, c2, c3, etc .. The current format of my repeater is: <table> <asp:Repeater ID="rptCompanies" Runat="server">
8
3026
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the way I'm going about doing this might be a little off. I'd appreciate some help. Below is the code I have thus far but I'm not sure how to reference the user control within the foreach loop. <asp:Panel ID="pnlRosterProfile" runat="Server" />
0
4094
by: uncensored | last post by:
Hello everyone, I'm fairly new at .Net and I have a repeater inside a repeater problem. I will attach my code to this message but basically what I am able to tell when I run my page it tells me that my second repeater has the following error, System.NullReferenceException: Object reference not set to an instance of an object. When I put a watch on I can see my second repeater is not being created because it is equal to "Nothing". I can...
3
10492
by: AlecL | last post by:
Hi All, I am trying to capture the value of a textbox as a result of a button click event in a repeater, but it can't find the textbox. Here is what I am trying to do in the code for the click event: Dim prodkey As String = CType(FindControl("txtProductkey"), TextBox).Text.ToString() Response.Redirect("store_shoppingcart.aspx?pkey=" & prodkey)
1
2311
by: Øyvind Isaksen | last post by:
I have a Repeater that dynamicly displayes some textboxes. Each Textbox has an ID like this (example): ID="10_20_textbox". The first number (10) describes what article this field is for, and the secound number (20) describes what article attribute this belongs to. In my code I need to loop through all the Items in my Repeater Control. My question is: Is it possible to use "FindControl" when the ID is dynamically generated (find part of...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.