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
- <asp:Repeater ID="repeater" runat="server">
- <ItemTemplate>
- </tr>
- <tr>
- <td>
- <img src="<%#DataBinder.Eval(Container.DataItem,"gdimg")%>" width="50px" height="50px" />
- </td>
- <td>
- <%#DataBinder.Eval(Container.DataItem,"gdname")%>
- </td>
- <td>
- <asp:textbox id="Textbox1" runat="server" MaxLength="2" Width="25" />/antal
- </td>
- </tr>
- <tr>
- <td><asp:literal id="t"
- text="<%#DataBinder.Eval(Container.DataItem,"id")%>" runat="server" visible="false" />
- <asp:
- <asp:button id="Button1" runat="server" text="Köp" onclick="Button1_Click" />
- </td>
- </ItemTemplate>
- </asp:Repeater>
- </tr>
- </table>
Expand|Select|Wrap|Line Numbers
- protected void Button1_Click(object sender, System.EventArgs e)
- {
- Button btn = sender as Button;
- Literal idd = btn.Parent.FindControl("t") as Literal;
- TextBox tb = btn.Parent.FindControl("TextBox1") as TextBox;
- if (tb != null)
- {
- Database db = new Database(Server.MapPath("App_Data/DB.mdb"));
- Response.Write(tb.Text);
- Response.Write(idd.Text);
- }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Page.IsPostBack == false)
- {
- Database db = new Database(Server.MapPath("App_Data/DB.mdb"));
- repeater.DataSource = db.ExecuteQuery("SELECT * FROM goods ORDER BY gdtype ASC");
- repeater.DataBind();
- db.Close();
- }
- if (Request.QueryString != null)
- {
- Database db = new Database(Server.MapPath("App_Data/DB.mdb"));
- string bokstav = Request.QueryString["rel"];
- repeater.DataSource = db.ExecuteQuery("SELECT * FROM goods WHERE gdtype LIKE '"+bokstav+"%'");
- repeater.DataBind();
- db.Close();
- }
- }
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 =)